Commit 1c34ed63 authored by Jean-Paul Saman's avatar Jean-Paul Saman

safe handling of realloc()

parent b167c3d8
...@@ -168,12 +168,12 @@ realloc_buffer( ...@@ -168,12 +168,12 @@ realloc_buffer(
if (!buffer_p || !max_elements_p) if (!buffer_p || !max_elements_p)
return NULL; return NULL;
void *buffer = *buffer_p;
if (*max_elements_p > num_elements) if (*max_elements_p > num_elements)
return buffer; return *buffer_p;
void *buffer;
num_elements += 4; num_elements += 4;
if ((buffer = realloc(buffer, num_elements * element_size)) == NULL) { if ((buffer = realloc(*buffer_p, num_elements * element_size)) == NULL) {
free(*buffer_p); free(*buffer_p);
*buffer_p = NULL; *buffer_p = NULL;
return NULL; return NULL;
......
...@@ -54,7 +54,7 @@ subpicture_add_association( ...@@ -54,7 +54,7 @@ subpicture_add_association(
) )
{ {
SubpictureAssociationP *assocs; SubpictureAssociationP *assocs;
assocs = realloc_buffer(&obj_subpicture->assocs, assocs = realloc_buffer((void **)&obj_subpicture->assocs,
&obj_subpicture->assocs_count_max, &obj_subpicture->assocs_count_max,
1 + obj_subpicture->assocs_count, 1 + obj_subpicture->assocs_count,
sizeof(obj_subpicture->assocs[0])); sizeof(obj_subpicture->assocs[0]));
...@@ -94,8 +94,14 @@ subpicture_remove_association( ...@@ -94,8 +94,14 @@ subpicture_remove_association(
unsigned int i; unsigned int i;
for (i = 0; i < obj_subpicture->assocs_count; i++) { for (i = 0; i < obj_subpicture->assocs_count; i++) {
if (obj_subpicture->assocs[i] == assoc) if (obj_subpicture->assocs[i] == assoc) {
return subpicture_remove_association_at(obj_subpicture, i); /* Free association at 'index' */
SubpictureAssociationP a = obj_subpicture->assocs[i];
ASSERT(a);
int idx = subpicture_remove_association_at(obj_subpicture, i);
free(a);
return idx;
}
} }
return -1; return -1;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment