diff --git a/gst-libs/gst/vaapi/gstvaapidecoder_objects.c b/gst-libs/gst/vaapi/gstvaapidecoder_objects.c
index 20d4f55..e7efab1 100644
--- a/gst-libs/gst/vaapi/gstvaapidecoder_objects.c
+++ b/gst-libs/gst/vaapi/gstvaapidecoder_objects.c
@@ -304,12 +304,21 @@ gst_vaapi_picture_decode (GstVaapiPicture * picture)
     status = vaRenderPicture (va_display, va_context, va_buffers, 2);
     if (!vaapi_check_status (status, "vaRenderPicture()"))
       return FALSE;
-
-    vaapi_destroy_buffer (va_display, &slice->param_id);
-    vaapi_destroy_buffer (va_display, &slice->data_id);
   }
 
   status = vaEndPicture (va_display, va_context);
+
+  for (i = 0; i < picture->slices->len; i++) {
+    GstVaapiSlice *const slice = g_ptr_array_index (picture->slices, i);
+    if (slice->param_id != VA_INVALID_ID) {
+      vaapi_destroy_buffer (va_display, &slice->param_id);
+      slice->param_id = VA_INVALID_ID;
+    }
+    if (slice->data_id != VA_INVALID_ID) {
+      vaapi_destroy_buffer (va_display, &slice->data_id);
+      slice->data_id = VA_INVALID_ID;
+    }
+  }
   if (!vaapi_check_status (status, "vaEndPicture()"))
     return FALSE;
   return TRUE;
