I've got a strange C problem that I've never seen before and can't figure out why its happening.
I'm writing a GTK app and I keep a linked list of data which is graphically represented as a CList. There are two ways in which items can be added; after the GUI loads it reads a configuration file building the list as it goes, or by adding new items via the GUI.
When reading the configuration file there are a set of functions to allocate a new item and populate its members, then calls a function to insert it into the linked list. when a new item is added via the GUI there is a function to read the data from the GUI, allocate the item and call the function to insert it.
The problem is that when reading configuration malloc hangs when allocate the new item.
If there is only 1 item the config file things work fine, and adding items from the GUi works perfectly on any number of adds/delets.
here is one of the functions that hang on malloc. This is called from the configuration loading function in another file.
The return value is only compared to NULL (never stored in a local variable)Code:struct os_list_item * os_list_new_other (char *new_title, char *new_unknown) { struct os_list_item *new_item = malloc (sizeof (struct os_list_item)); if (new_item == NULL) { return NULL; } new_item->title = new_title; new_item->type = OTHER; new_item->def = (os_list_size == -1 ? TRUE : FALSE); new_item->data = NULL; new_item->unknown = new_unknown; new_item->next = NULL; new_item->previous = NULL; os_list_put(new_item); return new_item; }
Also, when it hangs the CPU usage skyrockets.
I appologize for the long post, but I wanted to provide as much info as possible. If you need information, the CVS can be viewed here: http://sourceforge.net/cvs/?group_id=17229
Any help would be appreciated, and if you need more information I will be happy to provide
- Joseph Monti