commit a7e64c3f827b181514c32ceccf0e78ac964508b4 from: Stefan Sperling via: Thomas Adam date: Mon Jun 13 17:55:22 2022 UTC plug a memory leak in show_change(), line was leaked commit - 2f7ada206148cc1a3218669652926de2bdd3c04b commit + a7e64c3f827b181514c32ceccf0e78ac964508b4 blob - d2084af95607b92291656a333794b397f2e2a114 blob + 6e4ca499c4848af7cf18908b99903326a3bb66c8 --- got/got.c +++ got/got.c @@ -7480,6 +7480,7 @@ static const struct got_error * show_change(unsigned char status, const char *path, FILE *patch_file, int n, int nchanges, const char *action) { + const struct got_error *err; char *line = NULL; size_t linesize = 0; ssize_t linelen; @@ -7497,8 +7498,12 @@ show_change(unsigned char status, const char *path, FI printf(GOT_COMMIT_SEP_STR); while ((linelen = getline(&line, &linesize, patch_file)) != -1) printf("%s", line); - if (ferror(patch_file)) - return got_error_from_errno("getline"); + if (linelen == -1 && ferror(patch_file)) { + err = got_error_from_errno("getline"); + free(line); + return err; + } + free(line); printf(GOT_COMMIT_SEP_STR); printf("M %s (change %d of %d)\n%s this change? [y/n/q] ", path, n, nchanges, action);