From: Simon Doppler Date: Mon, 1 Dec 2014 19:24:20 +0000 (+0100) Subject: Correction of memory management errors X-Git-Url: https://git.danieliu.xyz/?a=commitdiff_plain;h=05e575979531e1f5597562e99294b0f00a8537ac;p=smdp.git Correction of memory management errors --- diff --git a/src/url.c b/src/url.c index e101013..f968dae 100644 --- a/src/url.c +++ b/src/url.c @@ -39,13 +39,15 @@ int url_add(const char *link_name, int link_name_length, const char *target, int assert(tmp); } - tmp -> link_name = calloc(link_name_length, sizeof(char)); + tmp -> link_name = calloc(link_name_length+1, sizeof(char)); assert(tmp->link_name); strncpy(tmp->link_name, link_name, link_name_length); + tmp->link_name[link_name_length] = '\0'; - tmp->target = calloc(target_length, sizeof(char)); + tmp->target = calloc(target_length+1, sizeof(char)); assert(tmp->target); strncpy(tmp->target, target, target_length); + tmp->target[target_length] = '\0'; tmp->x = x; tmp->y = y; @@ -57,8 +59,12 @@ int url_add(const char *link_name, int link_name_length, const char *target, int } char * url_get_target(int index) { + if (!init_ok) return NULL; + url_t *tmp = list; + if (!tmp) return NULL; + while (index > 0 && tmp && tmp->next) { tmp = tmp->next; index--;