为什么我在这里遇到内存访问冲突?

T.T*_*.T. 0 c memory webserver memory-leaks memory-management

此文件GoAhead WebServer的一部分,它实现了非常快速的块分配方案.

在第284行,Web服务器进程在随机时间崩溃.

 } 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
Run Code Online (Sandbox Code Playgroud)

这有什么可能的原因?

EDIT
bp是此头文件中指向此结构和联合的指针

typedef struct {
    union {
        void    *next;                          /* Pointer to next in q */
        int     size;                           /* Actual requested size */
    } u;
    int         flags;                          /* Per block allocation flags */
} bType;
Run Code Online (Sandbox Code Playgroud)

谢谢.

nos*_*nos 5

这是可能的原因.

  • 你搞砸了一些东西并破坏了你的一些数据结构或你的堆栈.

  • bQhead 是NULL或无效指针

  • q 超出了界限 bQhead

  • bp 是NULL或无效指针

使用调试器逐步执行代码,或使用printf调试,并查看bQhead,q,bp的值是否应该是它们.