调试glibc free():无效指针
Debug glibc free(): invalid pointer
我正在尝试调试最终抛出的代码
*** glibc detected *** ./build/smonitor: free(): invalid pointer:
这很有挑战性,因为我不使用免费。。。我看到了其他SO帖子中复制该问题的例子。。我需要关于如何调试的帮助。首先,我是一个C/C++n00b,所以我的指针技能正在开发中,但我没有做太多动态内存分配(我认为)。
我开始编写自己的"安全"应用程序,从相机中获取快照并将其写入NFS共享,最终我将显示每个相机的快照。现在,我从一台相机上拍摄照片,并在我的显示窗口中循环(使用opencv)。我可以跑一段时间(~小时),然后才能拿到堆芯。我创建了一个线程来运行窗口,我应该循环直到我的运行标志设置为false,然后我调用cvReleaseImage。。我不知道为什么这是失败的,任何指导都非常感谢!
// will be replaced with camera X filename on NFS share
std::string generate_filename()
{
static const char alphanum[] =
"0123456789"
"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
"abcdefghijklmnopqrstuvwxyz";
std::string filename = "";
std::stringstream ss;
for (int i = 0; i < 10; i++)
{
ss << alphanum[rand() % (sizeof(alphanum) - 1)];
}
ss << ".jpg";
printf("Generated filename: %sn", ss.str().c_str());
return ss.str();
}
std::string generate_file_path()
{
std::stringstream ss;
ss << CAPTURES_PATH << generate_filename();
return ss.str();
}
void capture_photo(std::string& filepath)
{
time_t now;
time_t end;
double seconds;
bool cancelCapture = false;
int count = 0;
CvCapture* capture = cvCreateCameraCapture(0);
printf(“Opened camera capturen");
IplImage* frame;
while(1)
{
frame = cvQueryFrame(capture);
if (!frame)
{
fprintf(stderr, "Could not read frame from video streamnn");
} else
{
cvShowImage(WINDOW, frame);
cvWaitKey(100);
if (get_snapshot_enabled()) // simulate delay between snapshots
{
filepath = generate_file_path();
printf("Saving imagen");
cvSaveImage(filepath.c_str(), frame);
break;
}
}
}
printf("Ending camera capturen");
cvReleaseCapture(&capture);
}
void* manage_window(void* arg)
{
time_t now;
time_t end;
double seconds = 0;
double stateSec;
int i = 0;
int rem = 0;
IplImage* images[10];
time_t lastUpdate;
time_t tDiff; // time diff
cvNamedWindow(WINDOW, CV_WINDOW_FREERATIO);
cvSetWindowProperty(WINDOW, CV_WND_PROP_FULLSCREEN, CV_WINDOW_FULLSCREEN);
std::string filepath;
time(&now);
int lastPos = 0;
while (1)
{
if (get_snapshot_enabled())
{
write_console_log("Going to capture photon");
// camera was selected
filepath = generate_file_path();
printf("Generated filepath: %sn", filepath.c_str());
capture_photo(filepath);
if (!filepath.empty())
{
printf("Received filepath: %sn", filepath.c_str());
time(&now);
images[lastPos] = cvLoadImage(filepath.c_str());
cvShowImage(WINDOW, images[lastPos]);
cvWaitKey(100);
if (lastPos == 10) lastPos = 0;
else lastPos++;
}
}
time(&end);
seconds = difftime(end, now);
if (seconds >= 5)
{
cvShowImage(WINDOW, images[ i % 10])
cvWaitKey(100);
i++;
time(&now);
}
// check if we're running
if (!get_running())
{
// log some error we're not running...
write_logs("Window thread exiting, not running...");
break;
}
}
for (i=0; i < 10; i++)
cvReleaseImage(&images[i]);
pthread_exit(NULL);
}
在void* manage_window(void* arg)
中有行
IplImage* images[10];
和
images[lastPos] = cvLoadImage(filepath.c_str());
if (lastPos == 10) lastPos = 0;
else lastPos++;
其中lastPos
可以增加到10,从而导致
images[10] = cvLoadImage(filepath.c_str());
即超出数组末尾的无效写入。我想像valgrind这样的东西会发现这一点。
相关文章:
- 如何实现容纳整数和无效指针的双向链表?
- 在基数排序中,我得到 munmap_chunk():无效指针和中止(核心转储).为什么?
- 应用地址清理器后,免费无效指针消失
- C++ 在具有数组成员的类上无效指针/双精度释放
- 不断得到分段错误和free()无效指针
- 使用无效指针初始化指针声明符的行为是否未定义?
- 结构作为参数的函数产生错误:free():无效指针:0x00007efd47b
- 无效指针、隔离标识符等
- c++ 无效指针从空闲列表中取消排队
- C++ munmap_chunk(): 无效指针:
- 为什么我的简单C++程序使用队列和 fstream 错误到无效指针
- 无效指针和非初始化的指针之间的差异
- 如何用无效指针初始化unique_ptr的向量
- 地址清理器在静态强制转换无效指针时报告错误
- MS4:Free(Free()无效指针0xB74E74E0 ***
- ***检测到的GLIBC *** MS2:free():无效指针:0xB7526FF4 ***
- 无效指针功能的输出
- 有人能告诉我这是如何在main()中实现的吗?(关于无效指针的问题)
- C++11使用智能指针,但得到无效指针
- 无效指针的相关性