c ++中的堆损坏错误

时间:2012-04-25 07:58:38

标签: c++ crash heap-memory

我在其中一台机器上遇到运行时错误。我已经在数百台机器上测试了我的应用程序但没有出现任何错误。错误窗口如下所示。

崩溃时应用程序显示错误窗口, enter image description here

如果我点击clickhere链接,它会显示下面的图像。 enter image description here

如果我调试代码,那么它显示在图像下方。 enter image description here

我不知道这是我的代码中的问题或操作系统安装中的任何问题请帮助我。因为我的应用程序在所有操作系统上运行,但只在一台计算机上出现错误。

代码如下:

rem->m_operationInProgress = false;
delete rem;  // from where error occur.
printf("after deleted.."); //this is not execute.

和析构函数是:

test::~test()
{
        printf("\n Enter in destructor.. ");

//  
//  m_isRunning = false;
//  Sleep(1000);

//  //-------------------------------------------- 1_4_2012
//  printf("\nCalling m_dataCollection->shutDown()");
////    printf("\n****calling  m_connect.shutDown();****");
//      printf("\nRPA :: 11....");
//  m_connect.shutDown();
//      printf("\nRPA :: 12....");
//  //printf("\n****after m_connect.shutDown();****");
//          printf("\nRPA :: 13....");
//  if(m_device != NULL)
//  {
//      //printf("\n****before delete  m_device;****");
//      printf("\nRPA :: 14....");
//      delete m_device;
//      printf("\nRPA :: 15....");
//      //printf("\n****after delete  m_device;****");
//  }
printf("\n Exited from destructor.. "); // this is also print on console.

}

它成功执行了print f然后崩溃。

1 个答案:

答案 0 :(得分:1)

您能告诉我们您正在测试的机器与您测试的“数百台机器”之间的区别吗?您的应用程序似乎是多线程的,并且将正在进行的操作设置为false似乎并不会立即告诉所有线程退出,尤其是在测试中的计算机速度较慢且单核时。所以你可能过早地删除了指针,而其他线程仍在使用它。因此,调用析构函数的原因,然后慢速线程在某处唤醒并尝试使用长期被删除的指针。

您可能需要在指针上添加锁定,以确保在所有线程都退出之前不会删除它。