Fix a memory leak in real_path
authorDodji Seketeli <dodji@redhat.com>
Thu, 18 Apr 2019 09:18:31 +0000 (11:18 +0200)
committerDodji Seketeli <dodji@redhat.com>
Thu, 18 Apr 2019 09:18:31 +0000 (11:18 +0200)
Running the testsuite with AddressSanitizer turned on flagged a memory
leak in real_path, in abg-tools-utils.cc.

Fixed thus.

* src/abg-tools-utils.cc (real_path): Fee the returned pointer of
realpath.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
src/abg-tools-utils.cc

index 58fe985e299b55d1b2f34b1af807f48c34f98ff3..9040a44a6c39d94e4c8073a00955cbddb0d8bf6c 100644 (file)
@@ -405,7 +405,10 @@ real_path(const string&path, string& result)
 
   char *realp = realpath(path.c_str(), NULL);
   if (realp)
-    result = realp;
+    {
+      result = realp;
+      free(realp);
+    }
 }
 
 /// Ensures #dir_path is a directory and is created.  If #dir_path is