diff --git a/src/bin/main.c b/src/bin/main.c index 8ed62e1..8e707d4 100644 --- a/src/bin/main.c +++ b/src/bin/main.c @@ -131,7 +131,6 @@ main(int argc, char **argv) { ecore_main_loop_begin(); evisum_ui_shutdown(ui); - free(ui); } elm_shutdown(); diff --git a/src/bin/system/machine.c b/src/bin/system/machine.c index 54ee47d..9a7c247 100644 --- a/src/bin/system/machine.c +++ b/src/bin/system/machine.c @@ -85,31 +85,23 @@ file_contents(const char *path) { FILE *f; char *buf, *tmp; - char byte[1]; - size_t count, n, bytes = 0; + size_t n = 1, len = 0; + const size_t block = 4096; f = fopen(path, "r"); if (!f) return NULL; - n = 1024; + buf = NULL; - buf = malloc(n * sizeof(byte) + 1); - if (!buf) return NULL; - - while ((count = (fread(byte, sizeof(byte), 1, f))) > 0) + while ((!feof(f)) && (!ferror(f))) { - bytes += sizeof(byte); - if (bytes == (n * sizeof(byte))) - { - n *= 2; - tmp = realloc(buf, n * sizeof(byte) + 1); - if (!tmp) return NULL; - buf = tmp; - } - memcpy(&buf[bytes - sizeof(byte)], byte, sizeof(byte)); + tmp = realloc(buf, ++n * (sizeof(char) * block) + 1); + if (!tmp) return NULL; + buf = tmp; + len += fread(buf + len, sizeof(char), block, f); } - if (!feof(f)) + if (ferror(f)) { free(buf); fclose(f); @@ -117,7 +109,7 @@ file_contents(const char *path) } fclose(f); - buf[bytes] = 0; + buf[len] = 0; return buf; } diff --git a/src/bin/ui/ui.c b/src/bin/ui/ui.c index 7e2244a..ff397c9 100644 --- a/src/bin/ui/ui.c +++ b/src/bin/ui/ui.c @@ -1520,6 +1520,8 @@ evisum_ui_shutdown(Ui *ui) evisum_ui_item_cache_free(ui->cache); eina_lock_free(&_lock); + + free(ui); } static void