summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Graf <tgraf@suug.ch>2011-08-11 15:06:29 +0200
committerThomas Graf <tgraf@suug.ch>2011-08-11 15:06:29 +0200
commitb5d081d1c9c9757e5e1d2e0babcace8b2a95fbe8 (patch)
tree20a7f47c49377402c0bc2f22bc1664574edb807f
parentd886de5e9d2455d5c111dd90e845b3ddb0c4c8b3 (diff)
downloadlibnl-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.c15
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);
+ }
}
}