From 4e0870bfeceb26fef3b1b6b136529cb3be711cfe 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 (cherry picked from commit 96e59f70f5bf6f58d9ff4ebf79981ac1d26e6299) --- medredis.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/medredis.c b/medredis.c index 0c3a0b0..121bbdc 100644 --- a/medredis.c +++ b/medredis.c @@ -768,6 +768,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); @@ -787,6 +790,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);