Skip to content

Commit

Permalink
Fixed: Various issues in B_DestroyAllClasses() which resulted in acce…
Browse files Browse the repository at this point in the history
…ssing beyond the end of the bindClasses array and a memory leak. @skyjake - feeling tired when you wrote that? :-)
  • Loading branch information
danij committed Mar 30, 2008
1 parent 6ae234e commit 7b3ee85
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions doomsday/engine/portable/src/b_class.c
Expand Up @@ -69,9 +69,14 @@ void B_DestroyAllClasses(void)

if(bindClasses)
{
for(i = 0; i < bindClassCount; ++i)
// Do not use the global bindClassCount to control the loop; it is
// changed as a sideeffect of B_DestroyClass() and also, the
// bindClasses array itself is shifted back to idx 0 afterwards.
int numBindClasses = bindClassCount;

for(i = 0; i < numBindClasses; ++i)
{
B_DestroyClass(bindClasses[i]);
B_DestroyClass(bindClasses[0]);
}
M_Free(bindClasses);
}
Expand Down Expand Up @@ -213,6 +218,7 @@ static void B_RemoveClass(bclass_t* bc)
{
memmove(&bindClasses[classIdx], &bindClasses[classIdx + 1],
sizeof(bclass_t*) * (bindClassCount - 1 - classIdx));

B_SetClassCount(bindClassCount - 1);
}
}
Expand Down

0 comments on commit 7b3ee85

Please sign in to comment.