commit - d93542d4d4d3693f2d977d334f0dbe3150e9329b
commit + 369eef86a8da74dcb95f04df3a266d9b8c8d2d9b
blob - be1e9bf1dfdb2efc4b2b139be32285d1519c4a3c
blob + 3ba1e4310ede9eee49ceb0718c034dac3fe71cd8
--- tog/tog.c
+++ tog/tog.c
return got_error_from_errno("calloc");
fread(buf, 1, len, infile);
- if (ferror(infile))
+ if (ferror(infile)) {
+ free(buf);
return got_error_from_errno("fread");
+ }
i = 0;
if (line_offsets && nlines) {
noffsets = 1;
*nlines = 1;
*line_offsets = calloc(1, sizeof(**line_offsets));
- if (*line_offsets == NULL)
+ if (*line_offsets == NULL) {
+ free(buf);
+ free(*line_offsets);
+ *line_offsets = NULL;
return got_error_from_errno("calloc");
+ }
/* Skip forward over end of first line. */
while (i < len) {
if (buf[i] == '\n')
}
}
- if (fflush(infile) != 0)
+ if (fflush(infile) != 0) {
+ free(buf);
+ free(*line_offsets);
return got_error_from_errno("fflush");
+ }
rewind(infile);
if (filesize)
*filesize = len;
+ free(buf);
+ free(*line_offsets);
return NULL;
}