Avoid freeing memory if vasprintf() failed
Founds this bugfix in Fedora's SOURCES for libnl. Not sure who the original author is but the bug should be fixed upstream as well.
This commit is contained in:
parent
d886de5e9d
commit
b5d081d1c9
1 changed files with 8 additions and 7 deletions
15
lib/utils.c
15
lib/utils.c
|
@ -815,13 +815,14 @@ static void dump_one(struct nl_dump_params *parms, const char *fmt,
|
|||
vfprintf(parms->dp_fd, fmt, args);
|
||||
else if (parms->dp_buf || parms->dp_cb) {
|
||||
char *buf = NULL;
|
||||
vasprintf(&buf, fmt, args);
|
||||
if (parms->dp_cb)
|
||||
parms->dp_cb(parms, buf);
|
||||
else
|
||||
strncat(parms->dp_buf, buf,
|
||||
parms->dp_buflen - strlen(parms->dp_buf) - 1);
|
||||
free(buf);
|
||||
if (vasprintf(&buf, fmt, args) >= 0) {
|
||||
if (parms->dp_cb)
|
||||
parms->dp_cb(parms, buf);
|
||||
else
|
||||
strncat(parms->dp_buf, buf,
|
||||
parms->dp_buflen - strlen(parms->dp_buf) - 1);
|
||||
free(buf);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue