From 91c157b14a822234621bc8af71e944839529e1ae Mon Sep 17 00:00:00 2001 From: James Booth Date: Fri, 9 Mar 2012 23:33:26 +0000 Subject: [PATCH] Update status in contact list on notification --- contact_list.c | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/contact_list.c b/contact_list.c index cd5b91b0..ae946d36 100644 --- a/contact_list.c +++ b/contact_list.c @@ -98,8 +98,20 @@ int contact_list_add(const char * const name, const char * const show) while(curr) { contact_t *curr_contact = curr->contact; - if (strcmp(curr_contact->name, name) == 0) + if (strcmp(curr_contact->name, name) == 0) { + if (curr_contact->show != NULL) { + free(curr_contact->show); + curr_contact->show = NULL; + + if (show != NULL) { + curr_contact->show = + (char *) malloc((strlen(show) + 1) * sizeof(char)); + strcpy(curr_contact->show, show); + } + } + return 0; + } prev = curr; curr = curr->next; @@ -159,7 +171,7 @@ static contact_t * _new_contact(const char * const name, const char * const show new->name = (char *) malloc((strlen(name) + 1) * sizeof(char)); strcpy(new->name, name); - if (show) { + if (show != NULL) { new->show = (char *) malloc((strlen(show) + 1) * sizeof(char)); strcpy(new->show, show); } else { @@ -173,7 +185,7 @@ static void _destroy_contact(contact_t *contact) { free(contact->name); - if (contact->show) { + if (contact->show != NULL) { free(contact->show); }