From 9013415593868b2d31a895e3f1f209fc21b58384 Mon Sep 17 00:00:00 2001 From: Richard Mudgett Date: Thu, 2 Nov 2017 18:40:20 -0500 Subject: Fix ast_(v)asprintf() malloc failure usage conditions. When (v)asprintf() fails, the state of the allocated buffer is undefined. The library had better not leave an allocated buffer as a result or no one will know to free it. The most likely way it can return failure is for an allocation failure. If the printf conversion fails then you actually have a threading problem which is much worse because another thread modified the parameter values. * Made __ast_asprintf()/__ast_vasprintf() set the returned buffer to NULL on failure. That is much more useful than either an uninitialized pointer or a pointer that has already been freed. Many uses won't have to check for failure to ensure that the buffer won't be double freed or prevent an attempt to free an uninitialized pointer. * stasis.c: Fixed memory leak in multi_object_blob_to_ami() allocated by ast_asprintf(). * ari/resource_bridges.c:ari_bridges_play_helper(): Remove assignment to the wrong thing which is now not needed even if assigning to the right thing. Change-Id: Ib5252fb8850ecf0f78ed0ee2ca0796bda7e91c23 --- apps/app_mixmonitor.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'apps') diff --git a/apps/app_mixmonitor.c b/apps/app_mixmonitor.c index b1579a70a..9f147768d 100644 --- a/apps/app_mixmonitor.c +++ b/apps/app_mixmonitor.c @@ -818,6 +818,8 @@ static int setup_mixmonitor_ds(struct mixmonitor *mixmonitor, struct ast_channel if (ast_asprintf(datastore_id, "%p", mixmonitor_ds) == -1) { ast_log(LOG_ERROR, "Failed to allocate memory for MixMonitor ID.\n"); + ast_free(mixmonitor_ds); + return -1; } ast_mutex_init(&mixmonitor_ds->lock); -- cgit v1.2.3