簡體   English   中英

奇數內存錯誤-錯誤分配

[英]Odd Memory Error — Bad Alloc

在WinPCap項目上工作。 嘗試執行一些基本的指針和內存操作,並且有很多錯誤。

我已將要嘗試的兩行與包含在一起。 另一個VSC ++項目中的相同行也可以正常工作。 這是我得到的錯誤

pktdump_ex.exe中0x75a79617處未處理的異常:Microsoft C ++異常:內存位置0x0012f8e4上的std :: bad_alloc。

#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;
};

我的猜測是,免費存儲被先前的一個語句損壞(可能是由於不正確地使用了pcap接口),並且當管理器檢測到該錯誤並拋出了錯誤的分配時,您才了解到下一個內存分配或釋放中的錯誤。

當您嘗試new並耗盡內存時,應引發std::bad_alloc 您可以檢查您的進程有多少可用內存嗎?

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM