test: Fix leaking stmt
authorLucas De Marchi <lucas.demarchi@intel.com>
Wed, 21 Aug 2013 17:31:11 +0000 (14:31 -0300)
committerLucas De Marchi <lucas.demarchi@intel.com>
Wed, 21 Aug 2013 17:36:21 +0000 (14:36 -0300)
Let's call sqlite3_finalize() on stmt so resources are freed and we
don't leak it:

==11116== 107,752 (856 direct, 106,896 indirect) bytes in 1 blocks are definitely lost in loss record 84 of 84
==11116==    at 0x4C2757B: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==11116==    by 0x5076816: ??? (in /usr/lib/libsqlite3.so.0.8.6)
==11116==    by 0x5052889: ??? (in /usr/lib/libsqlite3.so.0.8.6)
==11116==    by 0x505A6C7: ??? (in /usr/lib/libsqlite3.so.0.8.6)
==11116==    by 0x505A6EC: ??? (in /usr/lib/libsqlite3.so.0.8.6)
==11116==    by 0x50D27F0: ??? (in /usr/lib/libsqlite3.so.0.8.6)
==11116==    by 0x401F22: show (test.c:377)
==11116==    by 0x401913: main (test.c:481)

src/bin/test.c

index 9741b38..a1ea004 100644 (file)
@@ -358,7 +358,7 @@ show(lms_t *lms, const char *orig_path)
     char path[PATH_MAX];
     const char *db_path;
     sqlite3 *db;
-    sqlite3_stmt *stmt;
+    sqlite3_stmt *stmt = NULL;
     int r, len;
 
     if (!realpath(orig_path, path)) {
@@ -429,9 +429,9 @@ show(lms_t *lms, const char *orig_path)
         r = 0;
     }
 
-    sqlite3_reset(stmt);
-    sqlite3_clear_bindings(stmt);
-  close_and_exit:
+close_and_exit:
+    if (stmt)
+        sqlite3_finalize(stmt);
     sqlite3_close(db);
 
     return r;