1
0
mirror of https://git.FreeBSD.org/src.git synced 2024-10-20 02:38:43 +00:00

Fix memory leaks in error cases in libdtrace.

Submitted by:	Tom Rix <trix@juniper.net>
MFC after:	1 week
Differential Revision:	https://reviews.freebsd.org/D9705
This commit is contained in:
Mark Johnston 2017-02-23 17:56:24 +00:00
parent 74d9553e43
commit d935f34b8f
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=314154
2 changed files with 9 additions and 3 deletions

View File

@ -931,9 +931,11 @@ dt_provmod_open(dt_provmod_t **provmod, dt_fdlist_t *dfp)
* reallocate it. We normally won't need to do this
* because providers aren't being loaded all the time.
*/
if ((p = realloc(p_providers,len)) == NULL)
if ((p = realloc(p_providers,len)) == NULL) {
free(p_providers);
/* How do we report errors here? */
return;
}
p_providers = p;
} else
break;
@ -1148,8 +1150,10 @@ dt_vopen(int version, int flags, int *errp,
(void) fcntl(ftfd, F_SETFD, FD_CLOEXEC);
alloc:
if ((dtp = malloc(sizeof (dtrace_hdl_t))) == NULL)
if ((dtp = malloc(sizeof (dtrace_hdl_t))) == NULL) {
dt_provmod_destroy(&provmod);
return (set_open_errno(dtp, errp, EDT_NOMEM));
}
bzero(dtp, sizeof (dtrace_hdl_t));
dtp->dt_oflags = flags;

View File

@ -256,8 +256,10 @@ dt_strtab_insert(dt_strtab_t *sp, const char *str)
* Now copy the string data into our buffer list, and then update
* the global counts of strings and bytes. Return str's byte offset.
*/
if (dt_strtab_copyin(sp, str, len + 1) == -1)
if (dt_strtab_copyin(sp, str, len + 1) == -1) {
free(hp);
return (-1L);
}
sp->str_nstrs++;
sp->str_size += len + 1;