munmap_chunk:断言"ret == 0"失败
munmap_chunk: Assertion `ret == 0' failed
我写了一个使用vector和map的程序。
当我运行它时,我得到以下错误消息:
lru: malloc.c:3552: munmap_chunk:断言' ret == 0'失败。中止
这个错误信息是什么意思?
注:
当我运行我的程序与valgrind -它通过,没有'abort'。
下面是我的代码:
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <vector>
#include <map>
#include "byutr.h"
using namespace std;
///////////////////////////////////////////
/* DEFINE ZONE */
///////////////////////////////////////////
#define NUM_OF_ARGS 4
#define NUM_OF_DIFF_PAGES 100000
///////////////////////////////////////////
/* GLOBAL VARIABLES */
///////////////////////////////////////////
p2AddrTr tr;//a pre-defined struct
vector<uint32_t> stack;
vector<int> depths;
map<uint32_t, int> pages;
map<uint32_t, int>::iterator it;
int main(int argc, char **argv)
{
stack.reserve(NUM_OF_DIFF_PAGES);
FILE *ifp;//TODO remove!
// unsigned long i;//TODO int OR unsigned long??
int i;
unsigned long pCnt =0;
if(argc != NUM_OF_ARGS)
{
fprintf(stderr,"usage: lru <pageSize> <startAt> <numAccesses>n");
exit(1);
}
int pageSize = atoi(argv[1]);
int startAt = atoi(argv[2]);
int numAccesses = atoi(argv[3]);
int k;
//Skip some entries if needed
for(k=0;k< startAt;k++){
fread(&tr, sizeof(p2AddrTr), 1, stdin);
}
//size_t bytes = fread(&tr, sizeof(p2AddrTr),1, stdin);
//fread(&tr, sizeof(p2AddrTr),1, stdin); TODO here??
i = 0;
while((!feof(stdin)) && (i<numAccesses)){
fread(&tr, sizeof(p2AddrTr),1, stdin);
//prints the address of the memory access
printf("%08lx ", tr.addr);
cout<<endl;
int currAddr = (tr.addr)/pageSize;
if(pages.find(currAddr) == pages.end()){//New page
pCnt++;
//insert the new page to the map
pages.insert(pair<uint32_t, int>(currAddr,pCnt));
//insert the new page to the 'stack'
stack.push_back(currAddr);
}
else{//page already exists
size_t j;
//find the page in the stack
for(j=0;j<stack.size();j++){
if(stack[j] == currAddr){
cout << "passed stack[j]"<<endl;
depths.push_back(stack.size() - j);
break;
}
}
//move the page to the top of the stack
stack.erase(stack.begin() + (j-1));
stack.push_back(currAddr);
}
i++;
}
return (0);
}
我看到至少一个错误:
stack.erase(stack.begin() + (j-1));
如果j为0,则尝试擦除列表开始之前的元素,从而导致崩溃。
相关文章:
- 如果没有malloc,链表实现将失败
- 模板参数替换失败,并且未完成隐式转换
- 具有默认模板参数的多态类的模板推导失败
- 视图中的参数推导失败:take_while
- 链接到自行创建的dll失败
- 带有特殊路径部分的"std::filesystem::weakly_canonical"失败
- GetShortPathName在网络驱动器上使用中文文件夹时失败
- gcc和c++17的过载解析失败
- 为什么使用 P/Invoke 调用 dll 时,某些计算机中的 LoadLibrary 失败?
- 在WSL:configure_file上对config_file的每次调用都失败:配置文件时出现问题
- 使用 GCC 卸载的 OpenMP 卸载失败,并出现"Ptx assembly aborted due to errors"
- 使用cmake从源代码构建MySQL连接器/C++失败(与以前的声明冲突)
- 链接阶段在Ubuntu上失败,但在MacOS上失败
- 从父数组测试用例构造二叉树失败
- LibGit2 SSH身份验证失败
- 如何让LLDB在成功时退出,在失败时等待
- VS2017,C++包含目录与附加包含目录,子文件夹包含失败-但为什么
- 生成MRPT库时cmake配置失败
- 为什么除非添加括号,否则构造函数上的模板替换会失败?
- munmap_chunk:断言"ret == 0"失败