]> git.seodisparate.com - EN605.617.81.FA21_StephenSeo_DitheringProject/commitdiff
Fix memory leak with AVPacket, OpenCL logs
authorStephen Seo <seo.disparate@gmail.com>
Mon, 6 Dec 2021 06:51:49 +0000 (15:51 +0900)
committerStephen Seo <seo.disparate@gmail.com>
Mon, 6 Dec 2021 06:51:49 +0000 (15:51 +0900)
src/opencl_handle.cc
src/video.cc

index addfba87e79b2404b9407d11ccd606fe2dbcc39d..ce047fed621f89e5343835038b4716a63418e32a 100644 (file)
@@ -11,6 +11,7 @@ OpenCLContext::Ptr OpenCLContext::instance_ = {};
 OpenCLContext::OpenCLHandle::OpenCLHandle() : opencl_ptr_(), kernels_() {}
 
 OpenCLContext::OpenCLHandle::~OpenCLHandle() {
+  std::cout << "Destructing OpenCLHandle..." << std::endl;
   CleanupAllKernels();
   OpenCLContext::CleanupInstance();
 }
@@ -769,6 +770,7 @@ OpenCLContext::OpenCLContext() : context_(nullptr), queue_(nullptr) {
 }
 
 OpenCLContext::~OpenCLContext() {
+  std::cout << "Destructing OpenCLContext..." << std::endl;
   if (queue_) {
     clReleaseCommandQueue(queue_);
   }
index bac0b911915a1da00d8c4ab22ebb06b966dcd301..d604da52edddf7737a04f4f166d6b3c5e2569aa1 100644 (file)
@@ -295,6 +295,7 @@ bool Video::DitherVideo(const std::string &output_filename, Image *blue_noise,
         avcodec_close(enc_codec_context);
         avformat_free_context(avf_enc_context);
         av_frame_free(&frame);
+        av_packet_unref(pkt);
         av_packet_free(&pkt);
         avcodec_free_context(&codec_ctx);
         avformat_close_input(&avf_dec_context);
@@ -307,6 +308,7 @@ bool Video::DitherVideo(const std::string &output_filename, Image *blue_noise,
             avcodec_close(enc_codec_context);
             avformat_free_context(avf_enc_context);
             av_frame_free(&frame);
+            av_packet_unref(pkt);
             av_packet_free(&pkt);
             avcodec_free_context(&codec_ctx);
             avformat_close_input(&avf_dec_context);
@@ -316,6 +318,7 @@ bool Video::DitherVideo(const std::string &output_filename, Image *blue_noise,
         }
       }
     }
+    av_packet_unref(pkt);
   }
 
   // flush decoders