小编ber*_*ran的帖子

Valgrind说"绝对泄漏"但是它呢?

我正在尝试编写一个用于井字游戏的蒙特卡罗树搜索,但是在运行它时会出现真正的内存问题(例如我的计算机内存不足).

所以我决定调查情况valgrind.

下面是一个代码块,上面valgrind写着"绝对泄漏".

void player_init (Player **p, player_t symbol)
{
  *p = (Player *) malloc (sizeof (Player));
  (**p).symbol = symbol;
  (**p).score = 0;
}

void player_init_all (Player ***p)
{
  *p = (Player **) malloc (sizeof (Player *) * 2);
  for (int i = 0; i < 2; i++)
    {
      (*p)[i] = (Player *) malloc (sizeof (Player));
    }
  player_init (&(*p)[0], PLAYER1);
  player_init (&(*p)[1], PLAYER2);
}

void player_destroy (Player *p)
{
  free (p);
}
Run Code Online (Sandbox Code Playgroud)

在哪里Playerplayer_t …

c malloc free valgrind memory-leaks

0
推荐指数
1
解决办法
70
查看次数

标签 统计

c ×1

free ×1

malloc ×1

memory-leaks ×1

valgrind ×1