diff options
author | Thomas Graf <tgraf@suug.ch> | 2011-08-11 15:06:29 +0200 |
---|---|---|
committer | Thomas Graf <tgraf@suug.ch> | 2011-08-11 15:06:29 +0200 |
commit | b5d081d1c9c9757e5e1d2e0babcace8b2a95fbe8 (patch) | |
tree | 20a7f47c49377402c0bc2f22bc1664574edb807f | |
parent | d886de5e9d2455d5c111dd90e845b3ddb0c4c8b3 (diff) | |
download | libnl-b5d081d1c9c9757e5e1d2e0babcace8b2a95fbe8.tar.gz |
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.
-rw-r--r-- | lib/utils.c | 15 |
1 files changed, 8 insertions, 7 deletions
diff --git a/lib/utils.c b/lib/utils.c index 8eb068a..37ad4cc 100644 --- a/lib/utils.c +++ b/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); + } } } |