c ++:Program.exe中0x57B4B2CE(msvcr120d.dll)的未处理异常:0xC0000005:访问冲突读取位置0xCDCDCDC8

时间:2015-03-31 19:35:22

标签: c debugging pointers

我收到此错误

Unhandled exception at 0x57B4B2CE (msvcr120d.dll) in Program.exe: 0xC0000005: Access violation reading location 0xCDCDCDC8

它发生在代码的这一部分:

void Print_Function(char * output_file)
{
    f = 0;
    f = fopen(output_file,"w");

    for (int i = 0 ; i < count_total ; i++)
    {
        for (int j = 0 ; j < sizes[i] ; j++)
        {
            for (int k = 0 ; k < rules[i][j]->sizes_elements ; k++)
                if (k < rules[i][j]->sizes_elements - 1) fprintf(f,"%i ", elements[rules[i][j]->elements[k]]);
                else fprintf(f,"%i", elements[rules[i][j]->elements[k]]);

            fprintf(f,":%.3f:%i\n", rules[i][j]->measure_value,rules[i][j]->index);

            free(rules[i][j]->elements); rules[i][j]->elements = 0;
            free(rules[i][j]); rules[i][j] = 0;
        }

        free(rules[i]); rules[i] = 0;
    }

    fclose(f); f = 0;

    free(rules); rules = 0;
    free(size_rules); size_rules = 0;
    free(elements); elements = 0;
}

异常在代码的这一部分中启动

free(rules[i]); rules[i] = 0;    

在外循环的第一次迭代之后,是先前的自由做一些我没有注意到的事情,而不是像我期待的那样吗?

任何帮助表示感谢。

1 个答案:

答案 0 :(得分:-1)

Visual Studio使用几个假地址作为内存状态的指示符:

  • 0x00000000:nullptr或NULL
  • 0xFEEEFEEE:已被称为删除
  • 0xCDCDCDCD:已创建内存但未初始化。