0

all works fine but part way through the unload function I get

Program received signal SIGSEGV, Segmentation fault. 0xb7e929e5 in _int_free (av=0xb7fc9420 <main_arena>, p=0x8844168, have_lock=0) at malloc.c:3814
3814    malloc.c: No such file or directory.

my code for the unload function is:-

bool unload(void) 
{ 
    for(place = 0; place < 26; place++) 
    { 
        pointer = root; 
        checkArray(pointer); 
    } 
    return true; 
} 

void checkArray(node *pointer) 
{ 
    if (root->child[place] != NULL) 
    { 
        for (int i = 0 ; i < SIZE ; i++ ) 
        { 
            if (pointer->child[i] != NULL) 
            { 
                childNum = i; 
                current = pointer; 
                pointer = pointer->child[i]; 
                checkArray(pointer); 
                return; 
            } 
        } 
        free(pointer); 
        current->child[childNum]=NULL; 
        pointer = root; 
        checkArray(pointer); 
        return; 
    } 
    else 
    { 
        return; 
    } 
}

can anyone help

5
  • Probably its because you are trying to free something that you shouldn't but without seeing some of the code it is hard to tell exactly.
    – wallek876
    Commented Aug 11, 2015 at 11:10
  • [code]bool unload(void) { for(place = 0; place < 26; place++) { pointer = root; checkArray(pointer); } return true; } void checkArray(node *pointer) { if (root->child[place] != NULL) { for (int i = 0 ; i < SIZE ; i++ ) { if (pointer->child[i] != NULL) { childNum = i; current = pointer; pointer = pointer->child[i]; checkArray(pointer); return; } } free(pointer); current->child[childNum]=NULL; pointer = root; checkArray(pointer); return; } else { return; } }
    – biggrey54
    Commented Aug 11, 2015 at 11:15
  • [code]bool unload(void) { for(place = 0; place < 26; place++) { pointer = root; checkArray(pointer); } return true; } void checkArray(node *pointer) { if (root->child[place] != NULL) { for (int i = 0 ; i < SIZE ; i++ ) { if (pointer->child[i] != NULL) { childNum = i; current = pointer; pointer = pointer->child[i]; checkArray(pointer); return; } } free(pointer); current->child[childNum]=NULL; pointer = root; checkArray(pointer); return; } else { return; } }
    – biggrey54
    Commented Aug 11, 2015 at 19:36
  • 1
    Can you edit the question to include the code in it? This way is almost impossible for anybody to read it and answer you question.
    – wallek876
    Commented Aug 11, 2015 at 20:49
  • edited the question and code many thanks
    – biggrey54
    Commented Sep 11, 2015 at 21:31

0

You must log in to answer this question.

Browse other questions tagged .