我成功地将 cudaDecodeGL 从 windows 移植到 linux,它工作正常,但是在使用 valgrind 检查内存泄漏后,我发现其中有很多内存泄漏:
我查看了代码并寻找解决方案,我有一些问题:
1)我应该删除所有函数中所有声明的指针,我的意思是不删除指针会导致内存泄漏吗?
2)将windows程序移植到linux会不会造成内存泄漏问题,例如因为linux和windows中的内存管理机制?!?!
3)你能给我一个你在valgrind中遇到内存泄漏的过程吗?我的意思是如果valgrind告诉你你有这样的内存泄漏你会怎么做?valgrind 日志文件的一部分:
.
.
.
.
==10468== 754,864 (4,088 direct, 750,776 indirect) bytes in 1 blocks are definitely lost in loss record 136 of 137
==10468== at 0x4A069EE: malloc (vg_replace_malloc.c:270)
==10468== by 0x5B0A366: cuvidCreateVideoParser (in /usr/lib64/libnvcuvid.so.319.17)
==10468== by 0x40929E: VideoParser::VideoParser(VideoDecoder*, FrameQueue*, CUctx_st**) (in /home/admin/testcuda/de_3/cudaDecodeGL/3_Imaging/cudaDecodeGL/Far_Decoder)
==10468== by 0x4063F3: initCudaVideo() (in /home/admin/testcuda/de_3/cudaDecodeGL/3_Imaging/cudaDecodeGL/Far_Decoder)
==10468== by 0x404E8B: initCudaResources(int, char**, int*) (in /home/admin/testcuda/de_3/cudaDecodeGL/3_Imaging/cudaDecodeGL/Far_Decoder)
==10468== by 0x40561B: main (in /home/admin/testcuda/de_3/cudaDecodeGL/3_Imaging/cudaDecodeGL/Far_Decoder)
LEAK SUMMARY:
==10468== definitely lost: 7,608 bytes in 148 blocks
==10468== indirectly lost: 988,728 bytes in 907 blocks
==10468== possibly lost: 2,307,388 bytes in 59 blocks
==10468== still reachable: 413,278 bytes in 198 blocks
==10468== suppressed: 0 bytes in 0 blocks
如果您需要更多信息,请与我们联系。如果您认为我应该添加一些信息来明确我的问题,请告诉我该怎么做,我真的很感激。
更新 :
VideoParser::VideoParser(VideoDecoder *pVideoDecoder, FrameQueue *pFrameQueue, CUcontext *pCudaContext): hParser_(0)
{
assert(0 != pFrameQueue);
oParserData_.pFrameQueue = pFrameQueue;
assert(0 != pVideoDecoder);
oParserData_.pVideoDecoder = pVideoDecoder;
oParserData_.pContext = pCudaContext;
CUVIDPARSERPARAMS oVideoParserParameters;
memset(&oVideoParserParameters, 0, sizeof(CUVIDPARSERPARAMS));
oVideoParserParameters.CodecType = pVideoDecoder->codec();
oVideoParserParameters.ulMaxNumDecodeSurfaces = pVideoDecoder->maxDecodeSurfaces();
oVideoParserParameters.ulMaxDisplayDelay = 1; // this flag is needed so the parser will push frames out to the decoder as quickly as it can
oVideoParserParameters.pUserData = &oParserData_;
oVideoParserParameters.pfnSequenceCallback = HandleVideoSequence; // Called before decoding frames and/or whenever there is a format change
oVideoParserParameters.pfnDecodePicture = HandlePictureDecode; // Called when a picture is ready to be decoded (decode order)
oVideoParserParameters.pfnDisplayPicture = HandlePictureDisplay; // Called whenever a picture is ready to be displayed (display order)
CUresult oResult = cuvidCreateVideoParser(&hParser_, &oVideoParserParameters);
assert(CUDA_SUCCESS == oResult);
}
如您所见 cuvidCreateVideoParser 在共享库中,我该如何解决这种内存泄漏?