开发者

Why am I getting a memory access violation here?

开发者 https://www.devze.com 2023-02-06 22:17 出处:网络
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.

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 file

typedef 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 pointer

  • q is outside the bounds of bQhead

  • 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.

0

精彩评论

暂无评论...
验证码 换一张
取 消