mirror of
https://gitlab.freedesktop.org/pipewire/pipewire.git
synced 2025-11-03 09:01:54 -05:00
handle realloc error better
Make sure we free the old pointer, clear it and set the array size to 0. Use reallocarray where possible.
This commit is contained in:
parent
9e3b784b34
commit
ba7d410c3c
10 changed files with 240 additions and 120 deletions
|
|
@ -395,8 +395,12 @@ static int ensure_size(struct message *m, uint32_t size)
|
|||
|
||||
alloc = SPA_ROUND_UP_N(SPA_MAX(m->allocated + size, 4096u), 4096u);
|
||||
diff = alloc - m->allocated;
|
||||
if ((data = realloc(m->data, alloc)) == NULL)
|
||||
if ((data = realloc(m->data, alloc)) == NULL) {
|
||||
free(m->data);
|
||||
m->stat->allocated -= m->allocated;
|
||||
m->allocated = 0;
|
||||
return -errno;
|
||||
}
|
||||
m->stat->allocated += diff;
|
||||
m->stat->accumulated += diff;
|
||||
m->data = data;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue