fix(rtable): Potential memory leak in rte replace
If a route table entry was overlaid during the loading of
a new table there was a potential for leaking. Added unit
tests to better verify results of symtab cloning.
Change-Id: I6afecf52e9a48b36da3a06fa01867956a1a52261
Signed-off-by: E. Scott Daniels <daniels@research.att.com>
diff --git a/test/rt_static_test.c b/test/rt_static_test.c
index ce0eb25..972b767 100644
--- a/test/rt_static_test.c
+++ b/test/rt_static_test.c
@@ -45,6 +45,38 @@
/*
+ Driven by symtab foreach element of one space.
+ We count using the data as a counter.
+*/
+static void count_things( void* st, void* entry, char const* name, void* thing, void* vdata ) {
+ int* counter;
+
+ if( thing ) {
+ if( (counter = (int *) vdata) != NULL ) {
+ *counter++;
+ }
+ }
+}
+
+/*
+ Returns the number of entries in the table for the given class.
+*/
+static int count_entries( route_table_t* rt, int class ) {
+ int counter = 0;
+
+ if( ! rt ) {
+ return 0;
+ }
+ if( !rt->hash ) {
+ return 0;
+ }
+
+ rmr_sym_foreach_class( rt->hash, class, count_things, &counter ); // run each and update counter
+
+ return counter;
+}
+
+/*
This is the main route table test. It sets up a very specific table
for testing (not via the generic setup function for other test
situations).
@@ -59,6 +91,8 @@
int errors = 0; // number errors found
int i;
int k;
+ int c1; // general counters
+ int c2;
int mtype;
int value;
int alt_value;
@@ -142,8 +176,33 @@
}
}
- crt = uta_rt_clone( rt );
+ crt = uta_rt_clone( rt ); // clone only the endpoint entries
errors += fail_if_nil( crt, "cloned route table" );
+ if( crt ) {
+ c1 = count_entries( rt, 1 );
+ c2 = count_entries( crt, 1 );
+ errors += fail_not_equal( c1, c2, "cloned (endpoints) table entries space 1 count (b) did not match original table count (a)" );
+
+ c2 = count_entries( crt, 0 );
+ errors += fail_not_equal( c2, 0, "cloned (endpoints) table entries space 0 count (a) was not zero as expected" );
+ uta_rt_drop( crt );
+ }
+
+
+ crt = uta_rt_clone_all( rt ); // clone all entries
+ errors += fail_if_nil( crt, "cloned all route table" );
+
+ if( crt ) {
+ c1 = count_entries( rt, 0 );
+ c2 = count_entries( crt, 0 );
+ errors += fail_not_equal( c1, c2, "cloned (all) table entries space 0 count (b) did not match original table count (a)" );
+
+ c1 = count_entries( rt, 1 );
+ c2 = count_entries( crt, 1 );
+ errors += fail_not_equal( c1, c2, "cloned (all) table entries space 1 count (b) did not match original table count (a)" );
+ uta_rt_drop( crt );
+ }
+
ep = uta_get_ep( rt, "localhost:4561" );
errors += fail_if_nil( ep, "end point (fetch by name)" );
@@ -198,8 +257,6 @@
uta_rt_drop( rt );
- uta_rt_drop( crt );
-
if( (ctx = (uta_ctx_t *) malloc( sizeof( uta_ctx_t ) )) != NULL ) {
memset( ctx, 0, sizeof( *ctx ) );