From a4b4869af7c7dfc9dd16599e8d28645518f22874 Mon Sep 17 00:00:00 2001 From: Richard Fuchs Date: Thu, 28 Nov 2019 10:33:27 -0500 Subject: [PATCH] TT#71551 don't allocate zero-length memory blocks medredis_fetch_records() allocates memory for 0 return records, which in the calling code is understood as "no memory has been allocated", leading to a slow leak. Returning early is correct as the mem block pointer is set to NULL in this case. Change-Id: I69a2d397edd15cb9e4033531a218658c7ca93b12 --- medredis.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/medredis.c b/medredis.c index 20303ea..cef65e6 100644 --- a/medredis.c +++ b/medredis.c @@ -769,6 +769,9 @@ int medredis_fetch_records(med_callid_t *callid, (*count)++; } + if (!*count) + goto no_entries; + *entries = (med_entry_t*)malloc(*count * sizeof(med_entry_t)); if (!*entries) { L_ERROR("Failed to allocate memory for entries (cid '%s')\n", callid->value); @@ -788,6 +791,7 @@ int medredis_fetch_records(med_callid_t *callid, L_DEBUG("Added entry with cid '%s' and method '%s'\n", d->callid, d->sip_method); } +no_entries: g_list_free(records); g_list_free_full(keys, medredis_free_keys_list);