conn: call talloc_free before setting the pointer to NULL

in mgcp_rtp_codec_init() tallo_free is called after codec->subtype_name
and codec->audio_name are set to NULL. So talloc_free() always sees
NULL-pointers and never frees anything. This may cause a memory leak.

- call talloc_free() first, then set pointers to NULL

Change-Id: I7373819c3689d34811846f6f48f27568297b26e4
This commit is contained in:
Philipp Maier
2018-06-04 09:43:55 +02:00
committed by Harald Welte
parent 3c8ccb6724
commit b340f90c9e

View File

@@ -91,6 +91,10 @@ static int mgcp_alloc_id(struct mgcp_endpoint *endp, char *id)
/* Reset codec state and free memory */
static void mgcp_rtp_codec_init(struct mgcp_rtp_codec *codec)
{
/* see also mgcp_sdp.c, mgcp_set_audio_info() */
talloc_free(codec->subtype_name);
talloc_free(codec->audio_name);
codec->payload_type = -1;
codec->subtype_name = NULL;
codec->audio_name = NULL;
@@ -98,10 +102,6 @@ static void mgcp_rtp_codec_init(struct mgcp_rtp_codec *codec)
codec->frame_duration_den = DEFAULT_RTP_AUDIO_FRAME_DUR_DEN;
codec->rate = DEFAULT_RTP_AUDIO_DEFAULT_RATE;
codec->channels = DEFAULT_RTP_AUDIO_DEFAULT_CHANNELS;
/* see also mgcp_sdp.c, mgcp_set_audio_info() */
talloc_free(codec->subtype_name);
talloc_free(codec->audio_name);
}
/* Initialize rtp connection struct with default values */