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

堆腐败:原因是什么?

  •  17
  • Satbir  · 技术社区  · 15 年前

    我正在调查堆损坏导致的崩溃。由于这个问题非常重要,涉及到分析堆栈和转储结果,所以我决定对与崩溃相关的文件进行代码审查。

    坦率地说,我不知道堆何时会被破坏。

    如果您能提出可能导致堆腐败的方案,我将不胜感激。

    平台: Windows XP(Windows XP)

    Language: C++

    编译器: VC6

    13 回复  |  直到 6 年前
        1
  •  36
  •   cwap    15 年前

    • char *stuff = new char[10]; stuff[10] = 3;

        2
  •  13
  •   Coincoin    15 年前

        3
  •  6
  •   David Thornley    15 年前

    std::tr1::smart_ptr<>

        4
  •  6
  •   Komat    15 年前
        5
  •  3
  •   Community CDub    8 年前
        6
  •  3
  •   Stack Overflow is garbage    15 年前

        7
  •  3
  •   Alan    15 年前

        8
  •  2
  •   RED SOFT ADAIR    15 年前

        9
  •  2
  •   Red    15 年前

    constQ= new double* [num_equations];
    for(int i=0;i<num_equations;i++)
    {
    constQ[i]=new double[num_equations];
    for(int j=0;j<num_equations;j++)
    {
    constQ[i][j]=0.0;
    }
    .
    .
    .
    
    //Deleting/Freeing memory block 
    //Here the below only parent memory block is deleted, the child memory block is leaked.
    
    if(constQ!=NULL)
    {
    delete[] constQ;
    constQ=NULL
    } 
    //Correct way of deleting heap memory..First delet child block memory and then Parent block
    
    if(constQ!=NULL)
    {
    for(int i=0; i <num_equations;i++)
    {
    delete[] constQ[i];
    delete[] constQ;
    constQ=NULL
    }
    
        10
  •  1
  •   Paul Nathan    15 年前

        11
  •  1
  •   Max Lybbert    7 年前

    std::vector new[] delete[]

    if delete

    IBM's Rational Purify Intel Parallel Inspector

        13
  •  0
  •   Constantin    7 年前

    LPVOID WINAPI HeapAlloc(
      _In_ HANDLE hHeap,
      _In_ DWORD  dwFlags,
      _In_ SIZE_T dwBytes
    );
    

    dwFlags HEAP_GENERATE_EXCEPTIONS HEAP_NO_SERIALIZE HEAP_ZERO_MEMORY