Always use memory management wrappers
Use mem_*() wrappers instead of directly accessing libc functions when allocating/deallocating memory. Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
This commit is contained in:
parent
da6334cf38
commit
9ef5fe2191
@ -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)
|
static int parse_daterange(const char *str, time_t *date_from, time_t *date_to)
|
||||||
{
|
{
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
char *s = xstrdup(str);
|
char *s = mem_strdup(str);
|
||||||
char *p = strchr(s, ',');
|
char *p = strchr(s, ',');
|
||||||
|
|
||||||
if (!p)
|
if (!p)
|
||||||
@ -344,7 +344,7 @@ static int parse_daterange(const char *str, time_t *date_from, time_t *date_to)
|
|||||||
|
|
||||||
ret = 1;
|
ret = 1;
|
||||||
cleanup:
|
cleanup:
|
||||||
free(s);
|
mem_free(s);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -754,7 +754,7 @@ static void general_option_edit(int i)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
free(buf);
|
mem_free(buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* General configuration. */
|
/* General configuration. */
|
||||||
|
@ -45,7 +45,7 @@ static int find_basedir(const char *locale_info[], unsigned n, char **basedir)
|
|||||||
for (i = 0; i < n; i++) {
|
for (i = 0; i < n; i++) {
|
||||||
if (!locale_info[i])
|
if (!locale_info[i])
|
||||||
continue;
|
continue;
|
||||||
locale = strdup(locale_info[i]);
|
locale = mem_strdup(locale_info[i]);
|
||||||
|
|
||||||
asprintf(basedir, "%s/%s", DOCDIR, locale);
|
asprintf(basedir, "%s/%s", DOCDIR, locale);
|
||||||
if (io_dir_exists(*basedir)) {
|
if (io_dir_exists(*basedir)) {
|
||||||
@ -79,7 +79,7 @@ static int find_basedir(const char *locale_info[], unsigned n, char **basedir)
|
|||||||
|
|
||||||
cleanup:
|
cleanup:
|
||||||
if (locale)
|
if (locale)
|
||||||
free(locale);
|
mem_free(locale);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
4
src/io.c
4
src/io.c
@ -821,8 +821,8 @@ void io_reload_data(void)
|
|||||||
wins_launch_external(arg_todo);
|
wins_launch_external(arg_todo);
|
||||||
}
|
}
|
||||||
|
|
||||||
xfree(path_apts_backup);
|
mem_free(path_apts_backup);
|
||||||
xfree(path_todo_backup);
|
mem_free(path_todo_backup);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* We do not directly write to the data files here;
|
* We do not directly write to the data files here;
|
||||||
|
@ -56,8 +56,8 @@ void listbox_delete(struct listbox *lb)
|
|||||||
{
|
{
|
||||||
EXIT_IF(lb == NULL, "null pointer");
|
EXIT_IF(lb == NULL, "null pointer");
|
||||||
wins_scrollwin_delete(&(lb->sw));
|
wins_scrollwin_delete(&(lb->sw));
|
||||||
free(lb->type);
|
mem_free(lb->type);
|
||||||
free(lb->ch);
|
mem_free(lb->ch);
|
||||||
}
|
}
|
||||||
|
|
||||||
void listbox_resize(struct listbox *lb, int y, int x, int h, int w)
|
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;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
free(lb->type);
|
mem_free(lb->type);
|
||||||
free(lb->ch);
|
mem_free(lb->ch);
|
||||||
lb->type = mem_malloc(item_count * sizeof(unsigned));
|
lb->type = mem_malloc(item_count * sizeof(unsigned));
|
||||||
lb->ch = mem_malloc((item_count + 1) * sizeof(unsigned));
|
lb->ch = mem_malloc((item_count + 1) * sizeof(unsigned));
|
||||||
for (i = 0, ch = 0; i < item_count; i++) {
|
for (i = 0, ch = 0; i < item_count; i++) {
|
||||||
|
10
src/note.c
10
src/note.c
@ -201,7 +201,7 @@ void note_gc(void)
|
|||||||
struct apoint *apt = LLIST_GET_DATA(i);
|
struct apoint *apt = LLIST_GET_DATA(i);
|
||||||
if (apt->note) {
|
if (apt->note) {
|
||||||
tmph.hash = 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);
|
struct event *ev = LLIST_GET_DATA(i);
|
||||||
if (ev->note) {
|
if (ev->note) {
|
||||||
tmph.hash = 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);
|
struct recur_apoint *rapt = LLIST_GET_DATA(i);
|
||||||
if (rapt->note) {
|
if (rapt->note) {
|
||||||
tmph.hash = 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);
|
struct recur_event *rev = LLIST_GET_DATA(i);
|
||||||
if (rev->note) {
|
if (rev->note) {
|
||||||
tmph.hash = 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);
|
struct todo *todo = LLIST_GET_DATA(i);
|
||||||
if (todo->note) {
|
if (todo->note) {
|
||||||
tmph.hash = todo->note;
|
tmph.hash = todo->note;
|
||||||
free(HTABLE_REMOVE(htp, &gc_htable, &tmph));
|
mem_free(HTABLE_REMOVE(htp, &gc_htable, &tmph));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -53,7 +53,7 @@ void vector_free(vector_t *v)
|
|||||||
{
|
{
|
||||||
v->count = 0;
|
v->count = 0;
|
||||||
v->size = 0;
|
v->size = 0;
|
||||||
free(v->data);
|
mem_free(v->data);
|
||||||
v->data = NULL;
|
v->data = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -100,7 +100,7 @@ void vector_add(vector_t *v, void *data)
|
|||||||
{
|
{
|
||||||
if (v->count >= v->size) {
|
if (v->count >= v->size) {
|
||||||
v->size *= 2;
|
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;
|
v->data[v->count] = data;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user