From 9ef5fe2191c5d1d857bc4fe828c15268ba8caa90 Mon Sep 17 00:00:00 2001 From: Lukas Fleischer Date: Thu, 13 Oct 2016 08:20:35 +0200 Subject: Always use memory management wrappers Use mem_*() wrappers instead of directly accessing libc functions when allocating/deallocating memory. Signed-off-by: Lukas Fleischer --- src/args.c | 4 ++-- src/custom.c | 2 +- src/help.c | 4 ++-- src/io.c | 4 ++-- src/listbox.c | 8 ++++---- src/note.c | 10 +++++----- src/vector.c | 4 ++-- 7 files changed, 18 insertions(+), 18 deletions(-) (limited to 'src') diff --git a/src/args.c b/src/args.c index 3834f4a..afb4bfc 100644 --- a/src/args.c +++ b/src/args.c @@ -317,7 +317,7 @@ static time_t parse_datetimearg(const char *str) static int parse_daterange(const char *str, time_t *date_from, time_t *date_to) { int ret = 0; - char *s = xstrdup(str); + char *s = mem_strdup(str); char *p = strchr(s, ','); if (!p) @@ -344,7 +344,7 @@ static int parse_daterange(const char *str, time_t *date_from, time_t *date_to) ret = 1; cleanup: - free(s); + mem_free(s); return ret; } diff --git a/src/custom.c b/src/custom.c index 4e232e4..ef285e9 100644 --- a/src/custom.c +++ b/src/custom.c @@ -754,7 +754,7 @@ static void general_option_edit(int i) break; } - free(buf); + mem_free(buf); } /* General configuration. */ diff --git a/src/help.c b/src/help.c index 2de01cd..5cfe6d0 100644 --- a/src/help.c +++ b/src/help.c @@ -45,7 +45,7 @@ static int find_basedir(const char *locale_info[], unsigned n, char **basedir) for (i = 0; i < n; i++) { if (!locale_info[i]) continue; - locale = strdup(locale_info[i]); + locale = mem_strdup(locale_info[i]); asprintf(basedir, "%s/%s", DOCDIR, locale); if (io_dir_exists(*basedir)) { @@ -79,7 +79,7 @@ static int find_basedir(const char *locale_info[], unsigned n, char **basedir) cleanup: if (locale) - free(locale); + mem_free(locale); return ret; } diff --git a/src/io.c b/src/io.c index e0a8502..2dd5b34 100644 --- a/src/io.c +++ b/src/io.c @@ -821,8 +821,8 @@ void io_reload_data(void) wins_launch_external(arg_todo); } - xfree(path_apts_backup); - xfree(path_todo_backup); + mem_free(path_apts_backup); + mem_free(path_todo_backup); /* * We do not directly write to the data files here; diff --git a/src/listbox.c b/src/listbox.c index 333ddeb..a620adb 100644 --- a/src/listbox.c +++ b/src/listbox.c @@ -56,8 +56,8 @@ void listbox_delete(struct listbox *lb) { EXIT_IF(lb == NULL, "null pointer"); wins_scrollwin_delete(&(lb->sw)); - free(lb->type); - free(lb->ch); + mem_free(lb->type); + mem_free(lb->ch); } void listbox_resize(struct listbox *lb, int y, int x, int h, int w) @@ -95,8 +95,8 @@ void listbox_load_items(struct listbox *lb, int item_count) return; } - free(lb->type); - free(lb->ch); + mem_free(lb->type); + mem_free(lb->ch); lb->type = mem_malloc(item_count * sizeof(unsigned)); lb->ch = mem_malloc((item_count + 1) * sizeof(unsigned)); for (i = 0, ch = 0; i < item_count; i++) { diff --git a/src/note.c b/src/note.c index 4b274cd..0008a5f 100644 --- a/src/note.c +++ b/src/note.c @@ -201,7 +201,7 @@ void note_gc(void) struct apoint *apt = LLIST_GET_DATA(i); if (apt->note) { tmph.hash = apt->note; - free(HTABLE_REMOVE(htp, &gc_htable, &tmph)); + mem_free(HTABLE_REMOVE(htp, &gc_htable, &tmph)); } } @@ -209,7 +209,7 @@ void note_gc(void) struct event *ev = LLIST_GET_DATA(i); if (ev->note) { tmph.hash = ev->note; - free(HTABLE_REMOVE(htp, &gc_htable, &tmph)); + mem_free(HTABLE_REMOVE(htp, &gc_htable, &tmph)); } } @@ -217,7 +217,7 @@ void note_gc(void) struct recur_apoint *rapt = LLIST_GET_DATA(i); if (rapt->note) { tmph.hash = rapt->note; - free(HTABLE_REMOVE(htp, &gc_htable, &tmph)); + mem_free(HTABLE_REMOVE(htp, &gc_htable, &tmph)); } } @@ -225,7 +225,7 @@ void note_gc(void) struct recur_event *rev = LLIST_GET_DATA(i); if (rev->note) { tmph.hash = rev->note; - free(HTABLE_REMOVE(htp, &gc_htable, &tmph)); + mem_free(HTABLE_REMOVE(htp, &gc_htable, &tmph)); } } @@ -233,7 +233,7 @@ void note_gc(void) struct todo *todo = LLIST_GET_DATA(i); if (todo->note) { tmph.hash = todo->note; - free(HTABLE_REMOVE(htp, &gc_htable, &tmph)); + mem_free(HTABLE_REMOVE(htp, &gc_htable, &tmph)); } } diff --git a/src/vector.c b/src/vector.c index 10294a7..ef59f8f 100644 --- a/src/vector.c +++ b/src/vector.c @@ -53,7 +53,7 @@ void vector_free(vector_t *v) { v->count = 0; v->size = 0; - free(v->data); + mem_free(v->data); v->data = NULL; } @@ -100,7 +100,7 @@ void vector_add(vector_t *v, void *data) { if (v->count >= v->size) { v->size *= 2; - v->data = realloc(v->data, v->size * sizeof(void *)); + v->data = mem_realloc(v->data, v->size, sizeof(void *)); } v->data[v->count] = data; -- cgit v1.2.3