Skip to content

Commit

Permalink
Fixed: Memory access violation in binding context management
Browse files Browse the repository at this point in the history
Upon shutdown, an access violation due to mismanagement of memory in
the control binding bookkeeping resulted in an instant exit.
  • Loading branch information
danij-deng committed Jan 6, 2013
1 parent 7cab8e6 commit 8a42da7
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions doomsday/engine/src/ui/b_context.c
Expand Up @@ -270,7 +270,14 @@ void B_UpdateDeviceStateAssociations(void)

static void B_SetContextCount(int count)
{
bindContexts = M_Realloc(bindContexts, sizeof(bcontext_t*) * count);
if(count)
{
bindContexts = M_Realloc(bindContexts, sizeof(bcontext_t*) * count);
}
else
{
M_Free(bindContexts); bindContexts = 0;
}
bindContextCount = count;
}

Expand All @@ -288,15 +295,13 @@ static void B_InsertContext(bcontext_t* bc, int contextIdx)

static void B_RemoveContext(bcontext_t* bc)
{
int contextIdx = B_GetContextPos(bc);

if(contextIdx >= 0)
int contextIdx = B_GetContextPos(bc);
if(contextIdx >= 0 && bindContextCount > 1)
{
memmove(&bindContexts[contextIdx], &bindContexts[contextIdx + 1],
sizeof(bcontext_t*) * (bindContextCount - 1 - contextIdx));

B_SetContextCount(bindContextCount - 1);
}
B_SetContextCount(bindContextCount - 1);
}

/**
Expand Down

0 comments on commit 8a42da7

Please sign in to comment.