Fix three leaks in unit tests
authorAndres Notzli <andres.noetzli@gmail.com>
Sat, 5 Nov 2016 01:21:38 +0000 (18:21 -0700)
committerAndres Notzli <andres.noetzli@gmail.com>
Sat, 5 Nov 2016 05:24:25 +0000 (22:24 -0700)
The `testMultipleCollection` test case was allocating a
ListenerCollection without deleting it. The helper function
`countCommands` was not deleting the `Command`s returned from
`InteractiveShell::readCommand`. In the `testEmptyFileInput` and
`testSimpleFileInput` tests, the `filename` string was not deleted. This
commit fixes all issues.

test/unit/main/interactive_shell_black.h
test/unit/parser/parser_builder_black.h
test/unit/util/listener_black.h

index f1fce3cb8e7f4c29cb66c976da242fc023293df5..9ac81781cb7f76933251a24861b9160cbbfde102 100644 (file)
@@ -47,8 +47,12 @@ private:
   void countCommands(InteractiveShell& shell, 
                      int minCommands, 
                      int maxCommands) {
+    Command* cmd;
     int n = 0;
-    while( n <= maxCommands && shell.readCommand() != NULL ) { ++n; }
+    while( n <= maxCommands && (cmd = shell.readCommand()) != NULL ) {
+      ++n;
+      delete cmd;
+    }
     TS_ASSERT( n <= maxCommands );
     TS_ASSERT( n >= minCommands );
   }
index 42ebc2cf9aad58a26a61b135f689545ec04d59d4..61c426be9ad69114640e85dfee791bb7240cd5d8 100644 (file)
@@ -99,6 +99,7 @@ public:
 
     remove(filename);
     //    mkfifo(ptr, S_IWUSR | s_IRUSR);
+    delete filename;
   }
 
   void testSimpleFileInput() {
@@ -114,6 +115,7 @@ public:
                    );
 
     remove(filename);
+    delete filename;
   }
 
   void testEmptyStringInput() {
index 5319eacd19067e4292a2356a6c37acf868c25ade..b9ce7a3f7ca6e1ceaa3fa1f587694a7c7d819bff 100644 (file)
@@ -100,6 +100,7 @@ public:
     TS_ASSERT(collection->empty());
     std::string expected[4] = {"a", "b", "c", "c"};
     TS_ASSERT_EQUALS(d_events, mkMultiset(expected, 4));
+    TS_ASSERT_THROWS_NOTHING( delete collection );
   }
 
   void testRegisterMiddleTearDown() {