Strange, You may have to try
av_free(pkt.data); av_packet_unref(&pkt); av_free_packet(&pkt); ________________________________________ From: libav-api [[email protected]] on behalf of [email protected] [[email protected]] Sent: Friday, November 22, 2013 3:00 AM To: [email protected] Subject: libav-api Digest, Vol 33, Issue 8 Send libav-api mailing list submissions to [email protected] To subscribe or unsubscribe via the World Wide Web, visit https://lists.libav.org/mailman/listinfo/libav-api or, via email, send a message with subject or body 'help' to [email protected] You can reach the person managing the list at [email protected] When replying, please edit your Subject line so it is more specific than "Re: Contents of libav-api digest..." Today's Topics: 1. Re: memory leak (Michael Kannard) 2. Re: memory leak (Reuben Sant) ---------------------------------------------------------------------- Message: 1 Date: Thu, 21 Nov 2013 18:11:47 +0000 From: Michael Kannard <[email protected]> To: "[email protected]" <[email protected]> Subject: Re: [libav-api] memory leak Message-ID: <7af7c2579aa7444781e7f3ac4e55f96c1b7b7...@bl2prd0810mb373.namprd08.prod.outlook.com> Content-Type: text/plain; charset="us-ascii" When you call av_init_packet(..) This does not initialize the data memory for the packet. Therefore it is created when you call avcodec_encode_video2(.., dstFrame, got_pkt). If the memory is initialized when you call that function, then you are responsible for destroying the memory for the data field. av_free_packet(..) does not destroy that memory, so I think you would have to add a call to av_free(pkt->data), before the av_free_packet(). ________________________________________ From: libav-api [[email protected]] on behalf of [email protected] [[email protected]] Sent: Thursday, November 21, 2013 3:00 AM To: [email protected] Subject: libav-api Digest, Vol 33, Issue 7 Send libav-api mailing list submissions to [email protected] To subscribe or unsubscribe via the World Wide Web, visit https://lists.libav.org/mailman/listinfo/libav-api or, via email, send a message with subject or body 'help' to [email protected] You can reach the person managing the list at [email protected] When replying, please edit your Subject line so it is more specific than "Re: Contents of libav-api digest..." Today's Topics: 1. memory leak (Reuben Sant) ---------------------------------------------------------------------- Message: 1 Date: Thu, 21 Nov 2013 10:04:46 +0000 From: Reuben Sant <[email protected]> To: "[email protected]" <[email protected]> Subject: [libav-api] memory leak Message-ID: <4d0c0179982be04f9396736e68a6aefa02288a5...@hercules.imedia.com.mt> Content-Type: text/plain; charset="us-ascii" Hello, I have a simple module in our application that encodes a generated raw image and writes the encoded packets to file. The allocated image size is 1920x1080. Calls to avcodec_encode_video2 are allocating around 500MB of memory which is never freed up. I cannot find the source of this leak. Below I have described the procedure I'm using. Some notes: 1. if avcodec_encode_video2 does not return a got_pkt, I'm not freeing the packet because it was never allocated. Is that correct? 2. Am I correctly freeing frames with: av_freep and avcodec_free_frame ? 3. Does sws_scale simply takes the srcFrame and copies the scaled/converted image to the already allocated dstFrame, or is there any malloc involved internally? If so, I'm not freeing anything after this call. Thanks and Regards Reuben FUNCTION Start av_register_all() avformat_alloc_context(..) avcodec_find_encoder avformat_new_stream(..) avcodec_open2(..) srcFrame = avcodec_alloc_frame(..) dstFrame = avcodec_alloc_frame(..) av_image_alloc(srcFrame, ...) av_image_alloc(dstFrame, ...) sws_getContext(..) avio_open(..) avformat_write_header(..) End FUNCTION FUNCTION WriteLoop while (..) { fill srcFrame av_init_packet(..) sws_scale(srcFrame, dstFrame, ...) avcodec_encode_video2(.., dstFrame, got_pkt) if (got_pkt) WritePacket() } End FUNCTION FUNCTION WritePacket av_interleaved_write_frame(..) av_free_packet(..) End FUNCTION FUNCTION Stop got_pkt = 1 while (got_pkt) { avcodec_encode_video2(.., NULL, got_pkt) if (got_pkt) WritePacket() } av_write_trailer(..) av_freep(&srcFrame->data[0]); avcodec_free_frame(&srcFrame); av_freep(&dstFrame->data[0]); avcodec_free_frame(&dstFrame); //free the streams. av_freep(streams[i]->codec); av_freep(streams[i]); avio_close(..); av_free(avFormatContext); sws_freeContext(..); End FUNCTION ------------------------------ Subject: Digest Footer _______________________________________________ libav-api mailing list [email protected] https://lists.libav.org/mailman/listinfo/libav-api ------------------------------ End of libav-api Digest, Vol 33, Issue 7 **************************************** This e-mail and any attachments are intended only for use by the addressee(s) named herein and may contain confidential information. If you are not the intended recipient of this e-mail, you are hereby notified any dissemination, distribution or copying of this email and any attachments is strictly prohibited. If you receive this email in error, please immediately notify the sender by return email and permanently delete the original, any copy and any printout thereof. The integrity and security of e-mail cannot be guaranteed. ------------------------------ Message: 2 Date: Fri, 22 Nov 2013 09:32:03 +0000 From: Reuben Sant <[email protected]> To: Development with the libav* APIs <[email protected]> Subject: Re: [libav-api] memory leak Message-ID: <4d0c0179982be04f9396736e68a6aefa02288a5...@hercules.imedia.com.mt> Content-Type: text/plain; charset="ks_c_5601-1987" I tried : av_free(pkt.data), av_free_packet(&pkt); The second free does not execute. The Microsoft c++ compiler indicates a 'corruption of the heap. I think I'm freeing the same memory twice. Reuben -----Original Message----- From: libav-api [mailto:[email protected]] On Behalf Of Michael Kannard Sent: Il-?amis, 21 ta' Novembru 2013 19:12 To: [email protected] Subject: Re: [libav-api] memory leak When you call av_init_packet(..) This does not initialize the data memory for the packet. Therefore it is created when you call avcodec_encode_video2(.., dstFrame, got_pkt). If the memory is initialized when you call that function, then you are responsible for destroying the memory for the data field. av_free_packet(..) does not destroy that memory, so I think you would have to add a call to av_free(pkt->data), before the av_free_packet(). ________________________________________ From: libav-api [[email protected]] on behalf of [email protected] [[email protected]] Sent: Thursday, November 21, 2013 3:00 AM To: [email protected] Subject: libav-api Digest, Vol 33, Issue 7 Send libav-api mailing list submissions to [email protected] To subscribe or unsubscribe via the World Wide Web, visit https://lists.libav.org/mailman/listinfo/libav-api or, via email, send a message with subject or body 'help' to [email protected] You can reach the person managing the list at [email protected] When replying, please edit your Subject line so it is more specific than "Re: Contents of libav-api digest..." Today's Topics: 1. memory leak (Reuben Sant) ---------------------------------------------------------------------- Message: 1 Date: Thu, 21 Nov 2013 10:04:46 +0000 From: Reuben Sant <[email protected]> To: "[email protected]" <[email protected]> Subject: [libav-api] memory leak Message-ID: <4d0c0179982be04f9396736e68a6aefa02288a5...@hercules.imedia.com.mt> Content-Type: text/plain; charset="us-ascii" Hello, I have a simple module in our application that encodes a generated raw image and writes the encoded packets to file. The allocated image size is 1920x1080. Calls to avcodec_encode_video2 are allocating around 500MB of memory which is never freed up. I cannot find the source of this leak. Below I have described the procedure I'm using. Some notes: 1. if avcodec_encode_video2 does not return a got_pkt, I'm not freeing the packet because it was never allocated. Is that correct? 2. Am I correctly freeing frames with: av_freep and avcodec_free_frame ? 3. Does sws_scale simply takes the srcFrame and copies the scaled/converted image to the already allocated dstFrame, or is there any malloc involved internally? If so, I'm not freeing anything after this call. Thanks and Regards Reuben FUNCTION Start av_register_all() avformat_alloc_context(..) avcodec_find_encoder avformat_new_stream(..) avcodec_open2(..) srcFrame = avcodec_alloc_frame(..) dstFrame = avcodec_alloc_frame(..) av_image_alloc(srcFrame, ...) av_image_alloc(dstFrame, ...) sws_getContext(..) avio_open(..) avformat_write_header(..) End FUNCTION FUNCTION WriteLoop while (..) { fill srcFrame av_init_packet(..) sws_scale(srcFrame, dstFrame, ...) avcodec_encode_video2(.., dstFrame, got_pkt) if (got_pkt) WritePacket() } End FUNCTION FUNCTION WritePacket av_interleaved_write_frame(..) av_free_packet(..) End FUNCTION FUNCTION Stop got_pkt = 1 while (got_pkt) { avcodec_encode_video2(.., NULL, got_pkt) if (got_pkt) WritePacket() } av_write_trailer(..) av_freep(&srcFrame->data[0]); avcodec_free_frame(&srcFrame); av_freep(&dstFrame->data[0]); avcodec_free_frame(&dstFrame); //free the streams. av_freep(streams[i]->codec); av_freep(streams[i]); avio_close(..); av_free(avFormatContext); sws_freeContext(..); End FUNCTION ------------------------------ Subject: Digest Footer _______________________________________________ libav-api mailing list [email protected] https://lists.libav.org/mailman/listinfo/libav-api ------------------------------ End of libav-api Digest, Vol 33, Issue 7 **************************************** This e-mail and any attachments are intended only for use by the addressee(s) named herein and may contain confidential information. If you are not the intended recipient of this e-mail, you are hereby notified any dissemination, distribution or copying of this email and any attachments is strictly prohibited. If you receive this email in error, please immediately notify the sender by return email and permanently delete the original, any copy and any printout thereof. The integrity and security of e-mail cannot be guaranteed. _______________________________________________ libav-api mailing list [email protected] https://lists.libav.org/mailman/listinfo/libav-api ------------------------------ Subject: Digest Footer _______________________________________________ libav-api mailing list [email protected] https://lists.libav.org/mailman/listinfo/libav-api ------------------------------ End of libav-api Digest, Vol 33, Issue 8 **************************************** This e-mail and any attachments are intended only for use by the addressee(s) named herein and may contain confidential information. If you are not the intended recipient of this e-mail, you are hereby notified any dissemination, distribution or copying of this email and any attachments is strictly prohibited. If you receive this email in error, please immediately notify the sender by return email and permanently delete the original, any copy and any printout thereof. The integrity and security of e-mail cannot be guaranteed. _______________________________________________ libav-api mailing list [email protected] https://lists.libav.org/mailman/listinfo/libav-api
