HELP with function free() (stdlib.h)

Discussion in 'C' started by flexo87, Mar 2, 2008.

  1. flexo87

    flexo87 New Member

    Oct 26, 2007
    Likes Received:
    Trophy Points:
    Hi all! I'm wiriting a library that permits operations with graphs, i have some problem with the deallocation of memory. There is a function that takes a pointer to a graph (structure) as parameter, then it clear all the nodes of the graphs calling another function (that will clear also the edges). After removing the nodes, it just call the free((void*)g) where g is the pointer to the graph... but it seems that has no effect, because: the nodes and the edges are correctly deleted but the pointer to the graph is not NULL when the funciont retruns!! Here there is posted the code of the function:

    void free_graph (graph_t* g) {
    if (g) {
    node_t *tmp = g->nodes;
    while (tmp) {
    if (remove_node(g, tmp->label))
    fprintf(stderr, "Error removing node");
    tmp = tmp->next;

    The function remove_node() works correctly i've tested it.
    I'm a beginner is there someone ho can help me please?? THANKS!

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice