This file is part of the GoAhead WebServer, that implements a very fast block allocation scheme.
At line 284 the web server process crashes, at random times.
} else if ((bp = bQhead[q]) != NULL) {
/*
* Take first block off the relevant q if non-empty
*/
bQhead[q] = bp->u.next; //MEMORY ACCESS VIOLATION HERE
What are the possible reasons for this?
EDIT
bp is a pointer to this structure and union in this header filetypedef struct {
union {
void *next; 开发者_JS百科 /* Pointer to next in q */
int size; /* Actual requested size */
} u;
int flags; /* Per block allocation flags */
} bType;
Thanks.
Here's the possible reasons.
You've screwd something up and corrupted some of your data structures or your stack.
bQhead
is a NULL or invalid pointerq
is outside the bounds ofbQhead
bp
is a NULL or invalid pointer
Step through the code with a debugger, or use printf debugging, and see if the values if bQhead,q,bp are what they should be.
Give us more hints ...
Probably memory corruption by another thread, if it is random ...
my2c
Without running under a debugger, I would guess that q is out of range of 0 to B_MAXCLASS-1. The function that sets q, ballocGetSize()
does not do any bounds checking to make sure the block class stays within bounds.
A simple assertion to check that q is within bounds before deferencing would rule that possibilty out.
精彩评论