程序崩溃 - 检测到内存泄漏,我不明白为什么

时间:2013-12-27 08:41:22

标签: visual-studio-2012 crash command-line-arguments release-mode

它似乎是关于内存泄漏,我使用了函数_CrtDumpMemoryLeaks(); malloc函数之前和之后。 在malloc之前我什么都没得到,当_CrtDumpMemoryLeaks();在malloc之后运行时,我得到以下内容:

 Detected memory leaks!
                Dumping objects ->
                c:\users\omers66\documents\visual studio 2013\projects\assigment4\assigment4         \assignment4.c(150) : {66} normal block at 0x00F57338, 20 bytes long.
                Data: <                > CD CD CD CD CD CD CD CD CD CD CD CD CD CD CD CD 
                   Object dump complete.
                 The program '[7588] assigment4.exe' has exited with code 0 (0x0).

我想这意味着我遇到了第150行的问题? 但我看不出有什么不妥,这是该部分的代码:

struct Unit* add_unit(struct Unit* tree, int base, int newId, char*name)
{
    _CrtDumpMemoryLeaks();
    struct UnitList* tempUnitList;
    struct Unit* temp;
    struct Unit* returnValue = NULL;
    char* helpName;
    if (tree == NULL)
    {
        temp = ((struct Unit*)(malloc(sizeof(struct Unit))));     (line 150)
        _CrtDumpMemoryLeaks();
你能看到什么问题吗?

1 个答案:

答案 0 :(得分:0)

嗯,最终这是一个问题,没有给malloc提供足够的字符串空间,我忘了为'\ 0'添加一个额外的字节,因为我根据特定的字符串使用了sizeof

相关问题