I've never learned c language from books or anything so this maybe a simple problem.
What does the above code do?
----------------------------
The above is the code i have within a loop. The problem is somewhat obvious. Memory is allocated to 'ql' before its used and then its filled with values, then added to the main global 'quest_list'. 'ql' was supposed to be free'd after the values were passed to the global 'quest_list', but instead it clears part of the 'quest_list' becuase 'ql' still retains the reference.
What I have tried
-----------------
Now i didn't want to have it use new_ql over and over without free'ing it since that would probably be bad for memory use. I also tried before having it allocate memory to ql once (before the loop begins) and i've also tried not having a free_ql at all. (the end result was faulty, users would lockup the mud when they connect.. the quest_list produces infinite loops somehow).
To The Point
------------
What i was hoping to do is free_ql() but not losing the values, just killing the reference so 'ql' can be used when the loop reaches its beginning again. I'm unsure of how to do that. Any help would be appreciated :)
//QUESTLIST_DATA *quest_list; its global
QUESTLIST_DATA *ql;
word = fread_word( fp );
if ( !str_cmp(word,"QL") || !str_cmp(word,"QUESTLIST") ) {
ql = new_ql();
fread_ql ( ql, fp );
if ( quest_list != NULL )
ql->next = quest_list;
quest_list = ql;
free_ql(ql);
}
else if ( !str_cmp( word, "END" ) )
break;
What does the above code do?
----------------------------
The above is the code i have within a loop. The problem is somewhat obvious. Memory is allocated to 'ql' before its used and then its filled with values, then added to the main global 'quest_list'. 'ql' was supposed to be free'd after the values were passed to the global 'quest_list', but instead it clears part of the 'quest_list' becuase 'ql' still retains the reference.
What I have tried
-----------------
Now i didn't want to have it use new_ql over and over without free'ing it since that would probably be bad for memory use. I also tried before having it allocate memory to ql once (before the loop begins) and i've also tried not having a free_ql at all. (the end result was faulty, users would lockup the mud when they connect.. the quest_list produces infinite loops somehow).
To The Point
------------
What i was hoping to do is free_ql() but not losing the values, just killing the reference so 'ql' can be used when the loop reaches its beginning again. I'm unsure of how to do that. Any help would be appreciated :)