From 19e3e0bb949ccf10bc6e83cd81cbca294a99e747 Mon Sep 17 00:00:00 2001 From: Dmitri Pal Date: Wed, 9 Jun 2010 14:02:56 -0400 Subject: Addressing initialization issues. Fixing bug found by coverity. Tciket #519 --- common/collection/collection.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/common/collection/collection.c b/common/collection/collection.c index cde5db5d5..87ac32124 100644 --- a/common/collection/collection.c +++ b/common/collection/collection.c @@ -230,8 +230,12 @@ int col_allocate_item(struct collection_item **ci, const char *property, return ENOMEM; } - /* After we initialize "next" we can use delete_item() in case of error */ + /* After we initialize members we can use delete_item() in case of error */ item->next = NULL; + item->property = NULL; + item->data = NULL; + TRACE_INFO_NUMBER("About to set type to:", type); + item->type = type; /* Copy property */ item->property = strdup(property); @@ -246,7 +250,6 @@ int col_allocate_item(struct collection_item **ci, const char *property, TRACE_INFO_NUMBER("Item property length", item->property_len); TRACE_INFO_NUMBER("Item property strlen", strlen(item->property)); - /* Deal with data */ item->data = malloc(length); if (item->data == NULL) { @@ -254,11 +257,8 @@ int col_allocate_item(struct collection_item **ci, const char *property, col_delete_item(item); return ENOMEM; } - memcpy(item->data, item_data, length); - /* Deal with other properties of the item */ - TRACE_INFO_NUMBER("About to set type to:", type); - item->type = type; + memcpy(item->data, item_data, length); item->length = length; /* Make sure that data is NULL terminated in case of string */ -- cgit