mirror of
https://gitlab.torproject.org/tpo/core/tor.git
synced 2024-11-10 21:23:58 +01:00
Fix a memory leak in smartlist_string_remove.
svn:r5002
This commit is contained in:
parent
63dfe2447e
commit
8d70ae01b8
@ -121,7 +121,7 @@ void smartlist_remove(smartlist_t *sl, void *element) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** If there are any strings in sl equal to element, remove them.
|
/** If there are any strings in sl equal to element, remove and free them.
|
||||||
* Does not preserve order. */
|
* Does not preserve order. */
|
||||||
void
|
void
|
||||||
smartlist_string_remove(smartlist_t *sl, const char *element)
|
smartlist_string_remove(smartlist_t *sl, const char *element)
|
||||||
@ -131,6 +131,7 @@ smartlist_string_remove(smartlist_t *sl, const char *element)
|
|||||||
tor_assert(element);
|
tor_assert(element);
|
||||||
for (i = 0; i < sl->num_used; ++i) {
|
for (i = 0; i < sl->num_used; ++i) {
|
||||||
if (!strcmp(element, sl->list[i])) {
|
if (!strcmp(element, sl->list[i])) {
|
||||||
|
tor_free(sl->list[i]);
|
||||||
sl->list[i] = sl->list[--sl->num_used]; /* swap with the end */
|
sl->list[i] = sl->list[--sl->num_used]; /* swap with the end */
|
||||||
i--; /* so we process the new i'th element */
|
i--; /* so we process the new i'th element */
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user