diff options
author | Zdenek Kabelac <zkabelac@redhat.com> | 2020-01-29 16:30:16 +0100 |
---|---|---|
committer | Zdenek Kabelac <zkabelac@redhat.com> | 2020-02-04 17:22:06 +0100 |
commit | ac38b576f9f6daedf22a0d8472586bfe7de7c57e (patch) | |
tree | e9d9dda5224e2173e583a6eca687d3515ec3eb65 | |
parent | 62ad12d0d05d8ffa26df4f1b1b6ef3b2113420b1 (diff) | |
download | lvm2-ac38b576f9f6daedf22a0d8472586bfe7de7c57e.tar.gz |
dmsetup: no memleak on failed realocation
clang: keep old buf pointer for release on failing realloc() codepath.
-rw-r--r-- | libdm/dm-tools/dmsetup.c | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/libdm/dm-tools/dmsetup.c b/libdm/dm-tools/dmsetup.c index 269f86c9b..d01b8f2e8 100644 --- a/libdm/dm-tools/dmsetup.c +++ b/libdm/dm-tools/dmsetup.c @@ -1216,7 +1216,7 @@ out: static char *_slurp_stdin(void) { - char *buf, *pos; + char *newbuf, *buf, *pos; size_t bufsize = DEFAULT_BUF_SIZE; size_t total = 0; ssize_t n = 0; @@ -1245,10 +1245,12 @@ static char *_slurp_stdin(void) pos += n; if (total == bufsize - 1) { bufsize *= 2; - if (!(buf = realloc(buf, bufsize))) { + if (!(newbuf = realloc(buf, bufsize))) { log_error("Buffer memory extension to %" PRIsize_t " bytes failed.", bufsize); + free(buf); return NULL; } + buf = newbuf; } } while (1); |