mirror of
https://github.com/TheAlgorithms/C
synced 2024-11-21 21:11:57 +03:00
fix: remove double/unintended free
(#1143)
The call to realloc() already frees the previously allocated memory if necessary. By the man page of realloc(): "f the area pointed to was moved, a free(ptr) is done.", and free(): "If free(ptr) has already been called before, undefined behavior occurs.".
This commit is contained in:
parent
68bdbfb0a5
commit
1b3a1ca91e
@ -18,7 +18,6 @@ void *add(dynamic_array_t *da, const void *value)
|
|||||||
{
|
{
|
||||||
void **newItems =
|
void **newItems =
|
||||||
realloc(da->items, (da->capacity <<= 1) * sizeof(void **));
|
realloc(da->items, (da->capacity <<= 1) * sizeof(void **));
|
||||||
free(da->items);
|
|
||||||
|
|
||||||
da->items = newItems;
|
da->items = newItems;
|
||||||
}
|
}
|
||||||
@ -79,4 +78,4 @@ void *retrive_copy_of_value(const void *value)
|
|||||||
memcpy(value_copy, value, sizeof(void *));
|
memcpy(value_copy, value, sizeof(void *));
|
||||||
|
|
||||||
return value_copy;
|
return value_copy;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user