I just had a similar problem. In my case, it was connected to pointers in my linked list data structure. When I dynamically created a new list without initializing all the pointers inside the structure my program crashes outside GDB.
Here are my original data structures:
typedef struct linked_list {
node *head;
node *tail;
} list;
typedef struct list_node {
char *string;
struct list_node *next;
} node;
When I created a new "instance" of a list
specifying its head
and tail
, the program crashed outside GDB:
list *createList(void) {
list *newList = (list *) malloc(sizeof(list));
if (newList == NULL) return;
return newList;
}
Everything started to work normally after I changed my createList
function to this:
list *createList(void) {
list *newList = (list *) malloc(sizeof(list));
if (newList == NULL) return;
newList->head = (node *) 0;
newList->tail = (node *) 0;
return newList;
}
I hope it might help to someone in case of something similar to my example with non-initialized pointers.