1
0
mirror of git://sourceware.org/git/lvm2.git synced 2024-10-27 10:25:13 +03:00

dmsetup: no memleak on failed realocation

clang: keep old buf pointer for release on failing realloc() codepath.
This commit is contained in:
Zdenek Kabelac 2020-01-29 16:30:16 +01:00
parent 62ad12d0d0
commit ac38b576f9

View File

@ -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);