]> git.sesse.net Git - nageru/blobdiff - h264encode.cpp
Fix a leak in the H.264 encoder.
[nageru] / h264encode.cpp
index 04ad66995955fa01b10ec0c4cc793794c6762d6f..a16a5ea0b376dc4ed5678a48b7c4417ef433533e 100644 (file)
@@ -1469,6 +1469,12 @@ static int render_picture(void)
     va_status = vaRenderPicture(va_dpy, context_id, &pic_param_buf, 1);
     CHECK_VASTATUS(va_status, "vaRenderPicture");
 
+    // Supposedly vaRenderPicture() is supposed to destroy the buffer implicitly,
+    // but if we don't delete it here, we get leaks. The GStreamer implementation
+    // does the same.
+    va_status = vaDestroyBuffer(va_dpy, pic_param_buf);
+    CHECK_VASTATUS(va_status, "vaDestroyBuffer");
+
     return 0;
 }
 
@@ -1635,11 +1641,17 @@ static int render_slice(void)
 
     va_status = vaCreateBuffer(va_dpy, context_id, VAEncSliceParameterBufferType,
                                sizeof(slice_param), 1, &slice_param, &slice_param_buf);
-    CHECK_VASTATUS(va_status, "vaCreateBuffer");;
+    CHECK_VASTATUS(va_status, "vaCreateBuffer");
 
     va_status = vaRenderPicture(va_dpy, context_id, &slice_param_buf, 1);
     CHECK_VASTATUS(va_status, "vaRenderPicture");
-    
+
+    // Supposedly vaRenderPicture() is supposed to destroy the buffer implicitly,
+    // but if we don't delete it here, we get leaks. The GStreamer implementation
+    // does the same.
+    va_status = vaDestroyBuffer(va_dpy, slice_param_buf);
+    CHECK_VASTATUS(va_status, "vaDestroyBuffer");
+
     return 0;
 }
 
@@ -1725,6 +1737,7 @@ int H264Encoder::save_codeddata(storage_task task)
         }
         // TODO: Delayed frames.
         avcodec_free_frame(&frame);
+        av_free_packet(&pkt);
     }
 
 #if 0