代码之家  ›  专栏  ›  技术社区  ›  bobber205

奇数内存错误-分配错误

  •  -1
  • bobber205  · 技术社区  · 15 年前

    正在处理WinPCAP项目。尝试执行一些基本的指针和内存操作,但有很多错误。

    我已经包括了两行,我正试图与包括一起运行。 另一个vsc++项目中的相同行工作正常。这是我犯的错误

    0x75A79617英寸处未处理的异常 PKTUMPUXEXEX:微软C++ 异常:std::内存分配错误 位置0x0012F8E4..

    #include <stdlib.h>
    #include <stdio.h>
    #include <iostream>
    #include <string>
    #include "DataTypes.h"
    #include <sstream>
    
    #include "EthernetLayer.h"
    
    #include <pcap.h>
    
    int* testPointer = new int[2];
    delete[] testPointer;
    

    编辑: 发现一些有用的东西。 下面的代码段是导致winpcap库崩溃的原因。

    EthernetStructPointers* testData;
    testData = (EthernetStructPointers*)pkt_data;
    
    EthernetStruct newData;
    memcpy(newData.DEST_ADDRESS, testData->DEST_ADDRESS, 6);
    

    这些是结构的定义。

    struct EthernetStructPointers
    {
        u_char DEST_ADDRESS[6];
        u_char SOURCE_ADDRESS[6];
        u_char TYPE[2];
    };
    
    
    struct EthernetStruct
    {
        u_char DEST_ADDRESS[6];
        u_char SOURCE_ADDRESS[6];
        u_char TYPE[2];
    
        u_char* dataPointer;
    
        string DestAddress;
        string SourceAddress;
        string Type;
    
        int length;
    };
    
    2 回复  |  直到 15 年前
        1
  •  2
  •   Todd Gardner    15 年前

    我猜FreeStore被前面的一条语句破坏了(可能是由于不正确地使用了PCAP接口),而您只能在管理器检测到错误并抛出错误的alloc时了解下一个内存分配或释放的错误。

        2
  •  0
  •   Paul Stephenson    15 年前

    std::bad_alloc 当你试图扔的时候 new 一些东西,已经耗尽了记忆。你能检查一下你的进程有多少可用内存吗?