diff options
| author | Sadeep Madurange <sadeep@asciimx.com> | 2024-07-31 22:17:38 +0800 |
|---|---|---|
| committer | Sadeep Madurange <sadeep@asciimx.com> | 2024-07-31 22:17:38 +0800 |
| commit | d510de4cbf21c8f9c5e10a9cea8d908a4100ac36 (patch) | |
| tree | 2819f91795d15322e801afc302b5b5c31258e0bc /src | |
| parent | c8bacda3bb879a8301a9dc165f4cf792cd199bdb (diff) | |
| download | matrix-digital-rain-d510de4cbf21c8f9c5e10a9cea8d908a4100ac36.tar.gz | |
Remove freeing of already alloc memory on malloc fail.
Diffstat (limited to 'src')
| -rw-r--r-- | src/main.c | 28 |
1 files changed, 4 insertions, 24 deletions
@@ -77,43 +77,24 @@ static int mat_init(matrix *mat, const struct winsize *ws) { mat->rows = ws->ws_row + 1; mat->code = realloc(mat->code, sizeof mat->code[0] * mat->rows * mat->cols); - if (!mat->code) return 0; mat->rgb = realloc(mat->rgb, sizeof mat->rgb[0] * mat->rows * mat->cols); - - if (!mat->rgb) { - free(mat->code); + if (!mat->rgb) return 0; - } mat->shade = realloc(mat->shade, sizeof mat->shade[0] * mat->cols); - - if (!mat->shade) { - free(mat->code); - free(mat->rgb); + if (!mat->shade) return 0; - } mat->col = realloc(mat->col, sizeof mat->col[0] * mat->cols); - - if (!mat->col) { - free(mat->code); - free(mat->rgb); - free(mat->shade); + if (!mat->col) return 0; - } mat->row = realloc(mat->row, sizeof mat->row[0] * mat->cols); - - if (!mat->row) { - free(mat->code); - free(mat->rgb); - free(mat->col); - free(mat->shade); + if (!mat->row) return 0; - } for (i = 0; i < mat->cols; i++) { mat->row[i] = 0; @@ -260,7 +241,6 @@ int main(int argc, char *argv[]) { term_size(&ws); mat = (matrix){0}; - if (!mat_init(&mat, &ws)) { term_reset(); return 1; |
