assign realloc directly and no need to free, we die anyway - iomenu - interactive terminal-based selection menu HTML git clone git://bitreich.org/iomenu git://enlrupgkhuxnvlhsf6lc3fziv5h2hhfrinws65d7roiv6bfj7d652fid.onion/iomenu DIR Log DIR Files DIR Refs DIR Tags DIR README DIR LICENSE --- DIR commit e62b3c99fc9a7198c96ef70e15ad84c73534c84b DIR parent 90c2e1d2a25f901d709d94702f4ec2229c81990a HTML Author: Hiltjo Posthuma <hiltjo@codemadness.org> Date: Wed, 29 Nov 2017 20:56:29 +0100 assign realloc directly and no need to free, we die anyway Diffstat: M iomenu.c | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) --- DIR diff --git a/iomenu.c b/iomenu.c @@ -97,10 +97,8 @@ split_lines(char *buf) linec = 1; if (!(lv = linev = calloc(linec + 1, sizeof (char **)))) die("calloc"); - if (!(mv = matchv = calloc(linec + 1, sizeof (char **)))) { - free(linev); + if (!(mv = matchv = calloc(linec + 1, sizeof (char **)))) die("calloc"); - } *mv = *lv = b = buf; while ((b = strchr(b, '\n'))) { *b = '\0'; @@ -117,7 +115,7 @@ static void read_stdin(void) { size_t size, len, off; - char *buf, *b; + char *buf; size = BUFSIZ; off = 0; @@ -126,11 +124,8 @@ read_stdin(void) off += len; if (off >= size >> 1) { size <<= 1; - if (!(b = realloc(buf, size + 1))) { - free(buf); + if (!(buf = realloc(buf, size + 1))) die("realloc"); - } - buf = b; } } buf[off] = '\0';