mirror of
https://gitlab.freedesktop.org/pipewire/pipewire.git
synced 2025-11-16 07:00:00 -05:00
pod: handle realloc failure
When realloc fails, the original pointer is untouched so store the result of realloc somewhere else so that we don't cause a leak.
This commit is contained in:
parent
a9659d9dce
commit
5102e4cb8d
1 changed files with 5 additions and 4 deletions
|
|
@ -23,14 +23,15 @@ static int spa_pod_dynamic_builder_overflow(void *data, uint32_t size)
|
|||
struct spa_pod_dynamic_builder *d = (struct spa_pod_dynamic_builder*)data;
|
||||
int32_t old_size = d->b.size;
|
||||
int32_t new_size = SPA_ROUND_UP_N(size, d->extend);
|
||||
void *old_data = d->b.data;
|
||||
void *old_data = d->b.data, *new_data;
|
||||
|
||||
if (old_data == d->data)
|
||||
d->b.data = NULL;
|
||||
if ((d->b.data = realloc(d->b.data, new_size)) == NULL)
|
||||
if ((new_data = realloc(d->b.data, new_size)) == NULL)
|
||||
return -errno;
|
||||
if (old_data == d->data && d->b.data != old_data && old_size > 0)
|
||||
memcpy(d->b.data, old_data, old_size);
|
||||
if (old_data == d->data && new_data != old_data && old_size > 0)
|
||||
memcpy(new_data, old_data, old_size);
|
||||
d->b.data = new_data;
|
||||
d->b.size = new_size;
|
||||
return 0;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue