【问题标题】:Program crashes - Memory leak Detected, and i have no idea why程序崩溃 - 检测到内存泄漏,我不知道为什么
【发布时间】:2013-12-27 08:41:21
【问题描述】:

好像都是内存泄露,我用过_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();

你能看出什么不对吗?

【问题讨论】:

  • “命令参数”是什么意思?
  • 至少提供用于打印到txt的代码
  • 项目属性->调试->命令参数
  • 你在项目属性->调试->命令参数中设置了什么?请详细说明。
  • 好吧malloc 内存泄漏。伴随free时停止。

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


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-01-01
    • 1970-01-01
    • 2021-06-27
    • 2016-04-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多