Skip to content
Snippets Groups Projects
Commit cb38232e authored by Deucе's avatar Deucе :ok_hand_tone4:
Browse files

Fix most of the RIP issues found by coverity.

Most are simple memory leaks, but some would cause crashes, and
others would cause unexpected behaviour.
parent f2122630
No related branches found
No related tags found
No related merge requests found
...@@ -7253,6 +7253,7 @@ get_text_variable(const char * const var) ...@@ -7253,6 +7253,7 @@ get_text_variable(const char * const var)
vardef = bsearch(var, builtins, sizeof(builtins) / sizeof(builtins[0]), sizeof(builtins[0]), bicmp); vardef = bsearch(var, builtins, sizeof(builtins) / sizeof(builtins[0]), sizeof(builtins[0]), bicmp);
if (vardef == NULL) { if (vardef == NULL) {
puts("TODO: User variables"); puts("TODO: User variables");
return(calloc(1, 1));
} }
return vardef->func(var, vardef->data); return vardef->func(var, vardef->data);
} }
...@@ -7286,6 +7287,7 @@ rv_date(const char * const var, const void * const data) ...@@ -7286,6 +7287,7 @@ rv_date(const char * const var, const void * const data)
ctime_r(&now, str); ctime_r(&now, str);
return strdup(str); return strdup(str);
} }
break;
case 'Y': case 'Y':
snprintf(str, sizeof(str), "%02d", nlt.tm_mday); snprintf(str, sizeof(str), "%02d", nlt.tm_mday);
return strdup(str); return strdup(str);
...@@ -7726,10 +7728,9 @@ parse_string(const char *buf) ...@@ -7726,10 +7728,9 @@ parse_string(const char *buf)
char *p; char *p;
int ch; int ch;
   
char *ret = malloc(strlen(buf)); char *ret = malloc(strlen(buf) + 1);
if (ret == NULL) if (ret == NULL)
return ret; return ret;
p = ret;
for (p = ret; (ch = next_char(buf, &inpos)) > 0; inpos++) for (p = ret; (ch = next_char(buf, &inpos)) > 0; inpos++)
*(p++) = ch; *(p++) = ch;
*p = 0; *p = 0;
...@@ -8722,6 +8723,12 @@ add_button(int x1, int y1, int x2, int y2, int hotkey, int flags, char *text) ...@@ -8722,6 +8723,12 @@ add_button(int x1, int y1, int x2, int y2, int hotkey, int flags, char *text)
} }
   
draw_button(but, false); draw_button(but, false);
if (!but->flags.mouse) {
free(but->command);
free(but->icon);
free(but->label);
free(but);
}
} }
   
static void append_str(uint8_t **resp, size_t *size, size_t *pos, const char *str) static void append_str(uint8_t **resp, size_t *size, size_t *pos, const char *str)
...@@ -8790,6 +8797,8 @@ do_popup(const char * const str) ...@@ -8790,6 +8797,8 @@ do_popup(const char * const str)
if (soo == NULL) if (soo == NULL)
return NULL; return NULL;
question = strndup(p, soo - p); question = strndup(p, soo - p);
if (question == NULL)
return NULL;
soo += 2; soo += 2;
p = soo; p = soo;
opts = 0; opts = 0;
...@@ -8909,6 +8918,7 @@ do_popup(const char * const str) ...@@ -8909,6 +8918,7 @@ do_popup(const char * const str)
rip.x = x; rip.x = x;
rip.y = y; rip.y = y;
write_text(question); write_text(question);
free(question);
   
for (i = 0; i < opts; i++) { for (i = 0; i < opts; i++) {
set_pixel(x1 + 13, y1 + 27 + (i * 13), light); set_pixel(x1 + 13, y1 + 27 + (i * 13), light);
...@@ -9019,13 +9029,11 @@ handle_command_str(const char *incmd) ...@@ -9019,13 +9029,11 @@ handle_command_str(const char *incmd)
{ {
const char *p, *p2, *p3, *p4; const char *p, *p2, *p3, *p4;
char str[2]; char str[2];
const char *cmd;
   
if (incmd == NULL) if (incmd == NULL)
return; return;
cmd = strdup(incmd);
   
for (p = cmd; *p; p++) { for (p = incmd; *p; p++) {
// TODO: No way to send a ^ or a $ or a [ // TODO: No way to send a ^ or a $ or a [
if (*p == '^' || *p == '`') { // CTRL char if (*p == '^' || *p == '`') { // CTRL char
p++; p++;
...@@ -10125,6 +10133,7 @@ setpixel(x1, y1, xx); ...@@ -10125,6 +10133,7 @@ setpixel(x1, y1, xx);
} }
draw_line(argv[arg1 - 1].x, argv[arg1 - 1].y, argv[0].x, argv[0].y); draw_line(argv[arg1 - 1].x, argv[arg1 - 1].y, argv[0].x, argv[0].y);
} }
free(argv);
break; break;
case 's': // RIP_FILL_PATTERN case 's': // RIP_FILL_PATTERN
handled = true; handled = true;
...@@ -10505,7 +10514,7 @@ setpixel(x1, y1, xx); ...@@ -10505,7 +10514,7 @@ setpixel(x1, y1, xx);
if (fread(planes, row, 4, icn) != 4) { if (fread(planes, row, 4, icn) != 4) {
free(planes); free(planes);
free(pix->pixels); free(pix->pixels);
free(pix); FREE_AND_NULL(pix);
fclose(icn); fclose(icn);
break; break;
} }
...@@ -10517,6 +10526,7 @@ setpixel(x1, y1, xx); ...@@ -10517,6 +10526,7 @@ setpixel(x1, y1, xx);
*(op++) = ega_colours[co]; *(op++) = ega_colours[co];
} }
} }
if (pix) {
fclose(icn); fclose(icn);
free(planes); free(planes);
   
...@@ -10531,6 +10541,7 @@ setpixel(x1, y1, xx); ...@@ -10531,6 +10541,7 @@ setpixel(x1, y1, xx);
freepixels(pix); freepixels(pix);
} }
} }
}
break; break;
case 'K': // RIP_KILL_MOUSE_FIELDS case 'K': // RIP_KILL_MOUSE_FIELDS
/* /*
...@@ -10706,15 +10717,17 @@ setpixel(x1, y1, xx); ...@@ -10706,15 +10717,17 @@ setpixel(x1, y1, xx);
if (fwrite(planes, row, 4, icn) != 4) { if (fwrite(planes, row, 4, icn) != 4) {
fclose(icn); fclose(icn);
unlink(cache_path); unlink(cache_path);
free(planes); FREE_AND_NULL(planes);
fclose(icn); fclose(icn);
break; break;
} }
} }
if (planes) {
fwrite("F", 1, 1, icn); fwrite("F", 1, 1, icn);
fclose(icn); fclose(icn);
free(planes); free(planes);
} }
}
break; break;
} }
} }
...@@ -11096,6 +11109,11 @@ do_skypix(char *buf, size_t len) ...@@ -11096,6 +11109,11 @@ do_skypix(char *buf, size_t len)
} }
strlwr(fnt->entry[i].std.name); strlwr(fnt->entry[i].std.name);
flen = flength(fnt->entry[i].std.name); flen = flength(fnt->entry[i].std.name);
if (flen < 0) {
printf("TODO: Unable to read font %s size\n", fnt->entry[i].std.name);
free(fnt);
break;
}
font = fopen(fnt->entry[i].std.name, "rb"); font = fopen(fnt->entry[i].std.name, "rb");
if (font == NULL) { if (font == NULL) {
printf("TODO: Unable to open font %s\n", fnt->entry[i].std.name); printf("TODO: Unable to open font %s\n", fnt->entry[i].std.name);
...@@ -11105,6 +11123,7 @@ do_skypix(char *buf, size_t len) ...@@ -11105,6 +11123,7 @@ do_skypix(char *buf, size_t len)
free(fnt); free(fnt);
amiga_font = malloc(flen); amiga_font = malloc(flen);
if (amiga_font == NULL) { if (amiga_font == NULL) {
fclose(font);
break; break;
} }
fread(amiga_font, 1, flen, font); fread(amiga_font, 1, flen, font);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment