= 0) { } FCGI_Finis-6ren">
gpt4 book ai didi

c - Valgrind 和 FCGI : How to free all memory correctly after use

转载 作者:太空宇宙 更新时间:2023-11-03 23:26:45 25 4
gpt4 key购买 nike

使用这个简单的程序:

#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 中的错误。解决方法是直接调用库函数进行清理。 OS_LibShutdown() 释放由内部调用 FCGX_Init() 的 FCGI_Accept() 初始化的内存。对于多线程应用程序,您必须自己调用 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();

关于c - Valgrind 和 FCGI : How to free all memory correctly after use,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25323933/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com