From 59c4209347366a23fd3f8bfb0c15a811aefbde3b Mon Sep 17 00:00:00 2001 From: Cary R Date: Sun, 16 Oct 2011 19:34:51 -0700 Subject: [PATCH] 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. --- vpi/v2009_enum.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/vpi/v2009_enum.c b/vpi/v2009_enum.c index d5b857862..bd43cc09c 100644 --- a/vpi/v2009_enum.c +++ b/vpi/v2009_enum.c @@ -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;