aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNick Alcock <nick.alcock@oracle.com>2019-09-17 06:59:31 +0100
committerNick Alcock <nick.alcock@oracle.com>2019-09-24 14:06:32 +0100
commit6fa0bc1c30c6f099771d91c574cccbce5535ae75 (patch)
treeb39accd740b56f0284a6d54b2a60434de76f9b71
parent2ca5b4ab8a02b17ac4ee4a6f8474c288cb3fbef9 (diff)
downloadgdb-6fa0bc1c30c6f099771d91c574cccbce5535ae75.zip
gdb-6fa0bc1c30c6f099771d91c574cccbce5535ae75.tar.gz
gdb-6fa0bc1c30c6f099771d91c574cccbce5535ae75.tar.bz2
libctf: fix refcount leak in ctf_import
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.
-rw-r--r--libctf/ChangeLog5
-rw-r--r--libctf/ctf-open.c2
2 files changed, 7 insertions, 0 deletions
diff --git a/libctf/ChangeLog b/libctf/ChangeLog
index f084bac..d3fff1d 100644
--- a/libctf/ChangeLog
+++ b/libctf/ChangeLog
@@ -1,5 +1,10 @@
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.
* ctf-util.c (ctf_str_append_noerr): Define in terms of
ctf_str_append.
diff --git a/libctf/ctf-open.c b/libctf/ctf-open.c
index 4a95b7f..aedf390 100644
--- a/libctf/ctf-open.c
+++ b/libctf/ctf-open.c
@@ -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;
}