]> git.sesse.net Git - nageru/commitdiff
Fix some small memory leaks (some bigger remain).
authorSteinar H. Gunderson <sgunderson@bigfoot.com>
Sun, 17 Apr 2016 22:41:41 +0000 (00:41 +0200)
committerSteinar H. Gunderson <sgunderson@bigfoot.com>
Sun, 17 Apr 2016 22:41:41 +0000 (00:41 +0200)
h264encode.cpp

index 63ed499eec535900b604fdff06bef9008c783ea4..c1649e177e3c804a9e1c4883804c1d85c1c43270 100644 (file)
@@ -289,8 +289,8 @@ private:
        AVCodecContext *context_audio_file;
        AVCodecContext *context_audio_stream = nullptr;  // nullptr = don't code separate audio for stream.
 
-       AVAudioResampleContext *resampler_audio_file;
-       AVAudioResampleContext *resampler_audio_stream;
+       AVAudioResampleContext *resampler_audio_file = nullptr;
+       AVAudioResampleContext *resampler_audio_stream = nullptr;
 
        vector<float> audio_queue_file;
        vector<float> audio_queue_stream;
@@ -1851,7 +1851,6 @@ void init_audio_encoder(const string &codec_name, int bit_rate, AVCodecContext *
 
        *ctx = context_audio;
 
-       // FIXME: These leak on close.
        *resampler = avresample_alloc_context();
        if (*resampler == nullptr) {
                fprintf(stderr, "Allocating resampler failed.\n");
@@ -1929,8 +1928,10 @@ H264EncoderImpl::~H264EncoderImpl()
 {
        shutdown();
        av_frame_free(&audio_frame);
-
-       // TODO: Destroy context.
+       avresample_free(&resampler_audio_file);
+       avresample_free(&resampler_audio_stream);
+       avcodec_free_context(&context_audio_file);
+       avcodec_free_context(&context_audio_stream);
 }
 
 bool H264EncoderImpl::begin_frame(GLuint *y_tex, GLuint *cbcr_tex)