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.
This commit is contained in:
Nick Alcock 2019-09-17 06:59:31 +01:00
parent 9323dd869d
commit ad613f1d06
2 changed files with 7 additions and 0 deletions

View 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.

View 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;
}