From 4d019574e79eee40da5418cb23a35230a8c90d45 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Grisez?= <francois.grisez@belledonne-communications.com> Date: Tue, 22 Jan 2019 10:42:08 +0100 Subject: [PATCH] Add a setter for LinphoneCallLog's call ID in order to prevent memory leaks --- coreapi/call_log.c | 5 +++++ coreapi/private_functions.h | 1 + src/conference/session/call-session.cpp | 4 ++-- 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/coreapi/call_log.c b/coreapi/call_log.c index f228a90afb..a9eabde8e7 100644 --- a/coreapi/call_log.c +++ b/coreapi/call_log.c @@ -188,6 +188,11 @@ const char *linphone_call_log_get_call_id(const LinphoneCallLog *cl){ return cl->call_id; } +void linphone_call_log_set_call_id(LinphoneCallLog *cl, const char *call_id) { + if (cl->call_id) bctbx_free(cl->call_id); + cl->call_id = call_id ? bctbx_strdup(call_id) : NULL; +} + LinphoneCallDir linphone_call_log_get_dir(const LinphoneCallLog *cl){ return cl->dir; } diff --git a/coreapi/private_functions.h b/coreapi/private_functions.h index 8b94b8ff0c..4040e61c08 100644 --- a/coreapi/private_functions.h +++ b/coreapi/private_functions.h @@ -55,6 +55,7 @@ void linphone_call_notify_next_video_frame_decoded(LinphoneCall *call); LinphoneCall * linphone_call_new_outgoing(struct _LinphoneCore *lc, const LinphoneAddress *from, const LinphoneAddress *to, const LinphoneCallParams *params, LinphoneProxyConfig *cfg); LinphoneCall * linphone_call_new_incoming(struct _LinphoneCore *lc, const LinphoneAddress *from, const LinphoneAddress *to, LinphonePrivate::SalCallOp *op); LINPHONE_PUBLIC LinphoneCallLog *linphone_call_log_new(LinphoneCallDir dir, LinphoneAddress *from, LinphoneAddress * to); +void linphone_call_log_set_call_id(LinphoneCallLog *cl, const char *call_id); LinphonePlayer *linphone_call_build_player(LinphoneCall*call); LinphonePrivate::SalCallOp *linphone_call_get_op(const LinphoneCall *call); diff --git a/src/conference/session/call-session.cpp b/src/conference/session/call-session.cpp index 0ab0d82d08..30af1cd3bc 100644 --- a/src/conference/session/call-session.cpp +++ b/src/conference/session/call-session.cpp @@ -959,7 +959,7 @@ void CallSession::configure (LinphoneCallDir direction, LinphoneProxyConfig *cfg linphone_core_get_config(getCore()->getCCore()), "sip", "cnx_ip_to_0000_if_sendonly_enabled", 0 ) ); - d->log->call_id = ms_strdup(op->getCallId().c_str()); /* Must be known at that time */ + linphone_call_log_set_call_id(d->log, op->getCallId().c_str()); /* Must be known at that time */ } if (direction == LinphoneCallOutgoing) { @@ -1127,7 +1127,7 @@ int CallSession::startInvite (const Address *destination, const string &subject, d->setState(CallSession::State::Error, "Call failed"); } } else { - d->log->call_id = ms_strdup(d->op->getCallId().c_str()); /* Must be known at that time */ + linphone_call_log_set_call_id(d->log, d->op->getCallId().c_str()); /* Must be known at that time */ d->setState(CallSession::State::OutgoingProgress, "Outgoing call in progress"); } return result; -- GitLab