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
changes/71/35771/1
Richard Fuchs 7 years ago
parent 1aad65b82d
commit 740a003e88

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

Loading…
Cancel
Save