output_picture: unref pictures on allocation errors
diff --git a/src/lib.c b/src/lib.c
index d2aed23..1e5ea0b 100644
--- a/src/lib.c
+++ b/src/lib.c
@@ -265,8 +265,11 @@
 
     // Apply film grain to a new copy of the image to avoid corrupting refs
     int res = dav1d_picture_alloc_copy(out, in->p.w, in);
-    if (res < 0)
+    if (res < 0) {
+        dav1d_picture_unref(in);
+        dav1d_picture_unref(out);
         return res;
+    }
 
     switch (out->p.bpc) {
 #if CONFIG_8BPC