c中的内存泄漏

use*_*688 1 c c++

以下代码会导致内存泄漏

char * a()
{
   char * b = malloc(100);
   return b;
 }

B()
{ 
  char * c = a();
  free (c);
}
Run Code Online (Sandbox Code Playgroud)

Naw*_*waz 10

不,你毕竟释放了分配的内存.一般规则是,如果你要求free()每个malloc()函数调用,那么这意味着你没有泄漏内存.