All of lore.kernel.org
 help / color / mirror / Atom feed
* master - dmsetup: no memleak on failed realocation
@ 2020-02-04 16:22 Zdenek Kabelac
  0 siblings, 0 replies; only message in thread
From: Zdenek Kabelac @ 2020-02-04 16:22 UTC (permalink / raw)
  To: lvm-devel

Gitweb:        https://sourceware.org/git/?p=lvm2.git;a=commitdiff;h=ac38b576f9f6daedf22a0d8472586bfe7de7c57e
Commit:        ac38b576f9f6daedf22a0d8472586bfe7de7c57e
Parent:        62ad12d0d05d8ffa26df4f1b1b6ef3b2113420b1
Author:        Zdenek Kabelac <zkabelac@redhat.com>
AuthorDate:    Wed Jan 29 16:30:16 2020 +0100
Committer:     Zdenek Kabelac <zkabelac@redhat.com>
CommitterDate: Tue Feb 4 17:22:06 2020 +0100

dmsetup: no memleak on failed realocation

clang: keep old buf pointer for release on failing realloc() codepath.
---
 libdm/dm-tools/dmsetup.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/libdm/dm-tools/dmsetup.c b/libdm/dm-tools/dmsetup.c
index 269f86c..d01b8f2 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);
 




^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2020-02-04 16:22 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-02-04 16:22 master - dmsetup: no memleak on failed realocation Zdenek Kabelac

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.