summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSadeep Madurange <sadeep@asciimx.com>2024-07-31 22:17:38 +0800
committerSadeep Madurange <sadeep@asciimx.com>2024-07-31 22:17:38 +0800
commitd510de4cbf21c8f9c5e10a9cea8d908a4100ac36 (patch)
tree2819f91795d15322e801afc302b5b5c31258e0bc
parentc8bacda3bb879a8301a9dc165f4cf792cd199bdb (diff)
downloadmatrix-digital-rain-d510de4cbf21c8f9c5e10a9cea8d908a4100ac36.tar.gz
Remove freeing of already alloc memory on malloc fail.
-rw-r--r--src/main.c28
1 files changed, 4 insertions, 24 deletions
diff --git a/src/main.c b/src/main.c
index e3d2af4..737a7a8 100644
--- a/src/main.c
+++ b/src/main.c
@@ -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;