29 Jan, 2010, Bojack wrote in the 1st comment:
Votes: 0
I want to make sure im doing this right, if im deleting a clan out of a file that holds all my clans (1 file for all clans), for loading they are using calloc, am I setting this up right?

This is at the end of my clan delete function:
free_clan (pClan);        
pClan = NULL; //Change it from being accessed.
top_clan–;

sendch ("Clan deleted.\n\r", ch);
return TRUE;


And this is the call of free_clan:
void free_clan (CLAN_DATA *pClan)
{
int i;

free_string (pClan->name);
free_string (pClan->who_name);
free_string (pClan->leader);

for (i = 1; i < MAX_RANK; i++)
free_string (pClan->c_rank[i].rankname);

free (pClan);

pClan->next = clan_free;
clan_free = pClan;
return;
}

I dont believe I need the clan_free part cuz I believe I can just delete it out of the memory then use for (clan = clan_first; blah blah ->next) save_clan which would reset the file?
29 Jan, 2010, David Haley wrote in the 2nd comment:
Votes: 0
It does seem odd to keep track of a pointer that's been freed. Presumably yes, you can just delete the clan in memory and fix the linked list at the same time.
30 Jan, 2010, Sharmair wrote in the 3rd comment:
Votes: 0
You are mixing memory management models here. You seem to be using a memory recycling
system in your code, and freeing the patch of memory, then adding it to the free list is a VERY
bad thing. You do not show enough code here to see if you are also mixing models with your
allocating (both at boot up where there is nothing to recycle and when a new clan is created
online), or if you are removing the deleted clan correctly from the working clan list. The code
you show for your delete clan function would only be correct if pClan is already removed at
this point (and as a side note, if pClan is a local variable, it will go out of scope with the return
and both does not have to be NULLed and really if it is or not has nothing to do with it being
accessed as the comment seems to imply). If you want to directly calloc and free the memory,
you would remove the two lines about clan_free (in fact, you should not even have a clan_free)
and make sure ALL the places memory is allocated do NOT use some memory recycling function
(which also really should not exist). If however you want to use recycling, remove the free call
and make sure ALL your allocating uses the recycle functions (if you were using C++ you could
wrap them in a custom new and delete and you could switch models at will).
0.0/3