From: udemiko Date: Sat, 20 Aug 2016 16:34:11 +0000 (+0200) Subject: Fixed memory leaking, clarified calculation precedence X-Git-Tag: v0.3.0~44^2 X-Git-Url: https://chaos.moe/g/?a=commitdiff_plain;h=21d2068d75c6bfbd2dc714a1c2025eec5eec1d34;p=corbenik%2Fcorbenik.git Fixed memory leaking, clarified calculation precedence --- diff --git a/source/config-file.c b/source/config-file.c index 789d40f..cb0bc9c 100644 --- a/source/config-file.c +++ b/source/config-file.c @@ -112,6 +112,7 @@ load_config() config = (struct config_file*)malloc(sizeof(struct config_file) + FCRAM_SPACING / 2); memset(config, 0, sizeof(struct config_file) + FCRAM_SPACING / 2); enable_list = (uint8_t*)config + sizeof(struct config_file); + fclose(f); } // Zero on success. diff --git a/source/std/draw.c b/source/std/draw.c index efbb6e0..b57532e 100644 --- a/source/std/draw.c +++ b/source/std/draw.c @@ -190,7 +190,7 @@ void set_font(const char* filename) { abort("Invalid font file: w/h is 0 - not loaded\n"); } - unsigned int c_font_w = (new_w / 8) + (new_w % 8 ? 1 : 0); + unsigned int c_font_w = (new_w / 8) + ((new_w % 8) ? 1 : 0); font_data = malloc(c_font_w * new_h * (256 - ' ')); @@ -307,7 +307,7 @@ draw_character(uint8_t *screen, const unsigned int character, unsigned int ch_x, if (x >= width || y >= height) return; // OOB - unsigned int c_font_w = (font_w / 8) + (font_w % 8 ? 1 : 0); + unsigned int c_font_w = (font_w / 8) + ((font_w % 8) ? 1 : 0); for (unsigned int yy = 0; yy < font_h; yy++) { unsigned int xDisplacement = (x * SCREEN_DEPTH * height); diff --git a/source/std/fs.c b/source/std/fs.c index 814d09e..7bc4dd8 100644 --- a/source/std/fs.c +++ b/source/std/fs.c @@ -101,8 +101,10 @@ fopen(const char *filename, const char *mode) fp->mode = (mode[0] == 'r' ? FA_READ : (FA_WRITE | FA_OPEN_ALWAYS)); - if (f_open(&(fp->handle), filename, fp->mode)) + if (f_open(&(fp->handle), filename, fp->mode)) { + free(fp); return NULL; + } fp->is_open = 1;