libctf: fix refcount leak in ctf_import
authorNick Alcock <nick.alcock@oracle.com>
Tue, 17 Sep 2019 05:59:31 +0000 (06:59 +0100)
committerNick Alcock <nick.alcock@oracle.com>
Thu, 3 Oct 2019 16:04:56 +0000 (17:04 +0100)
Calling ctf_import (fp, NULL) to cancel out a pre-existing import leaked
the refcnt increment on the parent, so it could never be freed.

New in v4.

libctf/
* ctf-open.c (ctf_import): Do not leak a ctf_file_t ref on every
ctf_import after the first for a given file.

libctf/ChangeLog
libctf/ctf-open.c

index b7f12d8e092494c6cd2cf1242a5d9af497fe5e10..982c3355699d306244879a441a67ebffd1f5e809 100644 (file)
@@ -1,3 +1,8 @@
+2019-09-23  Nick Alcock  <nick.alcock@oracle.com>
+
+       * ctf-open.c (ctf_import): Do not leak a ctf_file_t ref on every
+       ctf_import after the first for a given file.
+
 2019-09-23  Nick Alcock  <nick.alcock@oracle.com>
 
        * ctf-impl.h (ctf_str_append_noerr): Declare.
index 4a95b7f38a5a33968bb3e7a47c535d1564784c31..aedf39086a2d288c3299260eaef15363a2a520b0 100644 (file)
@@ -1778,6 +1778,7 @@ ctf_import (ctf_file_t *fp, ctf_file_t *pfp)
 
   if (fp->ctf_parent != NULL)
     {
+      fp->ctf_parent->ctf_refcnt--;
       ctf_file_close (fp->ctf_parent);
       fp->ctf_parent = NULL;
     }
@@ -1793,6 +1794,7 @@ ctf_import (ctf_file_t *fp, ctf_file_t *pfp)
       fp->ctf_flags |= LCTF_CHILD;
       pfp->ctf_refcnt++;
     }
+
   fp->ctf_parent = pfp;
   return 0;
 }
This page took 0.027861 seconds and 4 git commands to generate.