summaryrefslogtreecommitdiff
path: root/atobm.c
diff options
context:
space:
mode:
authorAlan Coopersmith <alan.coopersmith@oracle.com>2022-04-09 16:11:45 -0700
committerAlan Coopersmith <alan.coopersmith@oracle.com>2022-04-09 16:25:12 -0700
commitb8090d0f5bee66ceb12cee2b63425efd74ad4610 (patch)
tree2d419369a4889a083bee35bddf05cc09413e2fc6 /atobm.c
parentc6b48ffeb65182bf5989df299c6a7fcccb3cb09a (diff)
atobm: close memory leaks
Fix leaks reported by Oracle Parfait (though they don't last long, since the program exits immediately after leaking): Error: Memory leak Memory leak [memory-leak] (CWE 401): Memory leak of pointer pointer allocated with _new_scan_list(bytes_per_scanline) at line 260 of atobm.c in function 'doit'. calloc called at line 180 in function '_new_scan_list' Allocated value returned to caller at line 193 pointer allocated at line 250 in function 'doit' with _new_scan_list(bytes_per_scanline) pointer leaks when (i + 1) >= <unknown> at line 275 and buf[0] != 0 at line 225. Error: Memory leak Memory leak [memory-leak] (CWE 401): Memory leak of pointer pointer allocated with _new_scan_list(bytes_per_scanline) at line 316 of atobm.c in function 'doit'. calloc called at line 180 in function '_new_scan_list' Allocated value returned to caller at line 193 pointer allocated at line 250 in function 'doit' with _new_scan_list(bytes_per_scanline) pointer leaks when slist != NULL at line 252 and (i + 1) >= <unknown> at line 275 and (i + 1) >= <unknown> at line 303. Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com>
Diffstat (limited to 'atobm.c')
-rw-r--r--atobm.c13
1 files changed, 9 insertions, 4 deletions
diff --git a/atobm.c b/atobm.c
index 90440ac..7d25906 100644
--- a/atobm.c
+++ b/atobm.c
@@ -243,7 +243,7 @@ doit (FILE *fp,
*newline = '\0';
len = strlen (cp);
- if (width == 0) {
+ if (head == NULL) {
width = len;
padded = ((width & 7) != 0);
bytes_per_scanline = (len + 7) / 8;
@@ -257,7 +257,7 @@ doit (FILE *fp,
fprintf (stderr,
"%s: line %d is %d characters wide instead of %d\n",
ProgramName, lineno, len, width);
- return;
+ goto bail;
}
if (slist->used + 1 >= slist->allocated) {
@@ -266,8 +266,7 @@ doit (FILE *fp,
if (!slist) {
fprintf (stderr, "%s: unable to allocate scan list\n", ProgramName);
- free(old);
- return;
+ goto bail;
}
}
@@ -308,5 +307,11 @@ doit (FILE *fp,
}
}
printf (" };\n");
+ bail:
+ for (slist = head; slist != NULL; slist = head) {
+ head = slist->next;
+ free(slist->scanlines);
+ free(slist);
+ }
return;
}