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 96e59f70f5)
changes/74/35774/1
Richard Fuchs 7 years ago
parent 5eae600eb5
commit 4e0870bfec

@ -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);

Loading…
Cancel
Save