Guarding free.

This commit is contained in:
johns 2001-04-22 20:55:15 +00:00
parent 18bb789519
commit e260f4566c
3 changed files with 27 additions and 9 deletions

View file

@ -348,16 +348,24 @@ int AddButton(int pos, int level, const char *icon_ident,
return 1;
}
/// FIXME: docu
/**
** Cleanup buttons.
*/
global void DoneButtons(void)
{
int z;
for (z = 0; z < UnitButtonCount; z++) {
DebugCheck(!UnitButtonTable[z]);
free(UnitButtonTable[z]->ValueStr);
free(UnitButtonTable[z]->Hint);
free(UnitButtonTable[z]->UnitMask);
if( UnitButtonTable[z]->ValueStr ) {
free(UnitButtonTable[z]->ValueStr);
}
if( UnitButtonTable[z]->Hint ) {
free(UnitButtonTable[z]->Hint);
}
if( UnitButtonTable[z]->UnitMask ) {
free(UnitButtonTable[z]->UnitMask);
}
free(UnitButtonTable[z]);
}
UnitButtonCount = 0;

View file

@ -1198,10 +1198,18 @@ local SCM CclDefineButton(SCM list)
}
AddButton(ba.Pos,ba.Level,ba.Icon.Name,ba.Action,ba.ValueStr,
ba.Allowed,ba.AllowStr,ba.Key,ba.Hint,ba.UnitMask);
free(ba.ValueStr);
free(ba.AllowStr);
free(ba.Hint);
free(ba.UnitMask);
if( ba.ValueStr ) {
free(ba.ValueStr);
}
if( ba.AllowStr ) {
free(ba.AllowStr);
}
if( ba.Hint ) {
free(ba.Hint);
}
if( ba.UnitMask ) {
free(ba.UnitMask);
}
return SCM_UNSPECIFIED;
}

View file

@ -1102,7 +1102,9 @@ local SCM CclDefineUpgrade(SCM list)
if( gh_eq_p(value,gh_symbol2scm("icon")) ) {
// Icon
free(icon);
if( icon ) {
free(icon);
}
icon=gh_scm2newstr(gh_car(list),NULL);
list=gh_cdr(list);
} else if( gh_eq_p(value,gh_symbol2scm("costs")) ) {