From 8336c91e9c7f5a672ebffecb9a0772892e197283 Mon Sep 17 00:00:00 2001 From: Aris Adamantiadis Date: Fri, 19 Jun 2009 10:18:24 +0200 Subject: [PATCH] Verify memory return codes in ssh_list functions --- include/libssh/priv.h | 2 +- libssh/misc.c | 9 +++++++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/include/libssh/priv.h b/include/libssh/priv.h index dab9aa73..4c380deb 100644 --- a/include/libssh/priv.h +++ b/include/libssh/priv.h @@ -723,7 +723,7 @@ struct ssh_iterator { struct ssh_list *ssh_list_new(void); void ssh_list_free(struct ssh_list *list); struct ssh_iterator *ssh_list_get_iterator(const struct ssh_list *list); -void ssh_list_add(struct ssh_list *list, const void *data); +int ssh_list_add(struct ssh_list *list, const void *data); void ssh_list_remove(struct ssh_list *list, struct ssh_iterator *iterator); /** @brief fetch the head element of a list and remove it from list diff --git a/libssh/misc.c b/libssh/misc.c index 8aa533e8..83a05207 100644 --- a/libssh/misc.c +++ b/libssh/misc.c @@ -152,7 +152,7 @@ const char *ssh_version(int req_version) { struct ssh_list *ssh_list_new(){ struct ssh_list *ret=malloc(sizeof(struct ssh_list)); if(!ret) - return ret; + return NULL; ret->root=ret->end=NULL; return ret; } @@ -174,13 +174,17 @@ struct ssh_iterator *ssh_list_get_iterator(const struct ssh_list *list){ static struct ssh_iterator *ssh_iterator_new(const void *data){ struct ssh_iterator *iterator=malloc(sizeof(struct ssh_iterator)); + if(!iterator) + return NULL; iterator->next=NULL; iterator->data=data; return iterator; } -void ssh_list_add(struct ssh_list *list,const void *data){ +int ssh_list_add(struct ssh_list *list,const void *data){ struct ssh_iterator *iterator=ssh_iterator_new(data); + if(!iterator) + return SSH_ERROR; if(!list->end){ /* list is empty */ list->root=list->end=iterator; @@ -189,6 +193,7 @@ void ssh_list_add(struct ssh_list *list,const void *data){ list->end->next=iterator; list->end=iterator; } + return SSH_OK; } void ssh_list_remove(struct ssh_list *list, struct ssh_iterator *iterator){