Remove a memory leak in enum next()/prev() code.

Some of the last changes I added to the enumeration next()/prev() code
introduced a memory leak under some situations. This patch fixes the
leak by freeing the iterator before the new one is created.
This commit is contained in:
Cary R 2011-10-16 19:34:51 -07:00 committed by Stephen Williams
parent 8977248ee2
commit 59c4209347
1 changed files with 7 additions and 1 deletions

View File

@ -306,6 +306,9 @@ static PLI_INT32 ivl_enum_method_next_prev_calltf(PLI_BYTE8*name)
if (strcmp(name, "$ivl_enum_method$next") == 0) {
/* Check to see if we need to wrap to the beginning. */
if (loc + count > enum_size) {
/* Free the current iterator before creating a new
* one that is at the beginning of the list. */
vpi_free_object(enum_list);
enum_list = vpi_iterate(vpiEnumConst, arg_enum);
assert(enum_list);
count -= (enum_size - loc);
@ -319,7 +322,10 @@ static PLI_INT32 ivl_enum_method_next_prev_calltf(PLI_BYTE8*name)
count = enum_size - count;
} else {
/* The element we want is before the current
* element (at the beginning of the list). */
* element (at the beginning of the list). Free
* the current iterator before creating a new
* one that is at the beginning of the list. */
vpi_free_object(enum_list);
enum_list = vpi_iterate(vpiEnumConst, arg_enum);
assert(enum_list);
count = loc - count;