Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/c/64.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Valgrind和FCGI:如何在使用后正确释放所有内存_C_Valgrind_Fastcgi - Fatal编程技术网

Valgrind和FCGI:如何在使用后正确释放所有内存

Valgrind和FCGI:如何在使用后正确释放所有内存,c,valgrind,fastcgi,C,Valgrind,Fastcgi,使用这个简单的程序: #include "fcgi_stdio.h" int main(void) { while(FCGI_Accept() >= 0) { } FCGI_Finish(); return(0); } 我从valgrind得到这个结果: Memcheck, a memory error detector Copyright (C) 2002-2013, and GNU GPL'd, by Julian Seward et al. Using V

使用这个简单的程序:

#include "fcgi_stdio.h"

int main(void)
{
  while(FCGI_Accept() >= 0)
  {
  }

  FCGI_Finish();

  return(0);
}
我从valgrind得到这个结果:

Memcheck, a memory error detector
Copyright (C) 2002-2013, and GNU GPL'd, by Julian Seward et al.
Using Valgrind-3.10.0.SVN and LibVEX; rerun with -h for copyright info
Command: ./val

HEAP SUMMARY:
  in use at exit: 768 bytes in 1 blocks
total heap usage: 1 allocs, 0 frees, 768 bytes allocated

768 bytes in 1 blocks are still reachable in loss record 1 of 1
  at 0x4C2AB80: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
  by 0x4E3D986: OS_LibInit (os_unix.c:171)
  by 0x4E3C80A: FCGX_Init (fcgiapp.c:2088)
  by 0x4E3C89A: FCGX_IsCGI (fcgiapp.c:1946)
  by 0x4E3CCA4: FCGI_Accept (fcgi_stdio.c:120)
  by 0x4006F6: main (in /home/[me]/kod/val)

LEAK SUMMARY:
  definitely lost: 0 bytes in 0 blocks
  indirectly lost: 0 bytes in 0 blocks
    possibly lost: 0 bytes in 0 blocks
  still reachable: 768 bytes in 1 blocks
       suppressed: 0 bytes in 0 blocks

For counts of detected and suppressed errors, rerun with: -v
ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)

使用FCGI后如何正确释放所有内存?

我遇到了同样的问题。似乎是FCGI中的一个bug。解决方法是直接调用库函数进行清理。OS_LibShutdown()通过内部调用FCGX_init()的FCGI_Accept()释放内存init。对于多线程应用程序,您必须自己调用FCGX_Init()

// Declare this (extern "C" is only required if from CPP)...
extern "C"
{
void OS_LibShutdown(void);
}

// From clean up code, call this...
OS_LibShutdown();

这可能是FCGI自身的一个缺陷。是否有FCGI_CLeanup之类的功能?似乎有一小部分内存没有被释放。如果它随着运行时间的增加而增加,那么您就有泄漏,否则您可以忽略它(或修复FCGI;)。所谓“运行时间”,我指的是在服务器运行(或进程,或任何情况下)的一段时间内,让FCGI按照您在生产中的方式进行操作。如果可以的话,我建议用生产代码测试它。