Skip to main content
added 727 characters in body
Source Link

I'm sooo close!! My code is running and printing out misspelled words but stopped at message "could not unload dictionary" (I tried on both large and small). However when I run Valgrind, it's reporting a successful memory freed without any leakage.

Here are the screen shots of Valgrind enter image description here
enter image description here

below is my codes for unload

// recursive function for freeing children memory

void del_trie(node* ptr)

{

for(int i = 0; i < ALPHABETS; i++)
    if(ptr->children[i] != NULL)
        del_trie(ptr->children[i]);

free(ptr);

return;

}

/**

  • Unloads dictionary from memory. Returns true if successful else false. */

bool unload(void)

{

node* current = root;

del_trie(current);

if(root != NULL);
    return false;

return true;

}

Can someone Plzzz help?? Thanks beforehand.

Edited code:

// recursive function for freeing children memory

void del_trie(node* ptr)

{

for(int i = 0; i < ALPHABETS; i++)
{
    if(ptr->children[i] != NULL)
        del_trie(ptr->children[i]);

    ptr->children[i] = NULL;
}

ptr = NULL;
free(ptr);
return;

}

/**

  • Unloads dictionary from memory. Returns true if successful else false. */

bool unload(void)

{

node* current = root;

del_trie(current);

root = NULL;
free(root);
    
if(root != NULL);
    return false;

return true;

}

enter image description here

I'm sooo close!! My code is running and printing out misspelled words but stopped at message "could not unload dictionary" (I tried on both large and small). However when I run Valgrind, it's reporting a successful memory freed without any leakage.

Here are the screen shots of Valgrind enter image description here
enter image description here

below is my codes for unload

// recursive function for freeing children memory

void del_trie(node* ptr)

{

for(int i = 0; i < ALPHABETS; i++)
    if(ptr->children[i] != NULL)
        del_trie(ptr->children[i]);

free(ptr);

return;

}

/**

  • Unloads dictionary from memory. Returns true if successful else false. */

bool unload(void)

{

node* current = root;

del_trie(current);

if(root != NULL);
    return false;

return true;

}

Can someone Plzzz help?? Thanks beforehand.

I'm sooo close!! My code is running and printing out misspelled words but stopped at message "could not unload dictionary" (I tried on both large and small). However when I run Valgrind, it's reporting a successful memory freed without any leakage.

Here are the screen shots of Valgrind enter image description here
enter image description here

below is my codes for unload

// recursive function for freeing children memory

void del_trie(node* ptr)

{

for(int i = 0; i < ALPHABETS; i++)
    if(ptr->children[i] != NULL)
        del_trie(ptr->children[i]);

free(ptr);

return;

}

/**

  • Unloads dictionary from memory. Returns true if successful else false. */

bool unload(void)

{

node* current = root;

del_trie(current);

if(root != NULL);
    return false;

return true;

}

Can someone Plzzz help?? Thanks beforehand.

Edited code:

// recursive function for freeing children memory

void del_trie(node* ptr)

{

for(int i = 0; i < ALPHABETS; i++)
{
    if(ptr->children[i] != NULL)
        del_trie(ptr->children[i]);

    ptr->children[i] = NULL;
}

ptr = NULL;
free(ptr);
return;

}

/**

  • Unloads dictionary from memory. Returns true if successful else false. */

bool unload(void)

{

node* current = root;

del_trie(current);

root = NULL;
free(root);
    
if(root != NULL);
    return false;

return true;

}

enter image description here

Source Link

pset5 unload printed failed to unload but pass valgrind with no leak?

I'm sooo close!! My code is running and printing out misspelled words but stopped at message "could not unload dictionary" (I tried on both large and small). However when I run Valgrind, it's reporting a successful memory freed without any leakage.

Here are the screen shots of Valgrind enter image description here
enter image description here

below is my codes for unload

// recursive function for freeing children memory

void del_trie(node* ptr)

{

for(int i = 0; i < ALPHABETS; i++)
    if(ptr->children[i] != NULL)
        del_trie(ptr->children[i]);

free(ptr);

return;

}

/**

  • Unloads dictionary from memory. Returns true if successful else false. */

bool unload(void)

{

node* current = root;

del_trie(current);

if(root != NULL);
    return false;

return true;

}

Can someone Plzzz help?? Thanks beforehand.