diff --git a/ffmpeg.c b/ffmpeg.c
index bbd30190cbd61d16a7765b5ceed4cecf4a087f88..105efbcb22bf23902c2685fd64d18f5e58baea74 100644
--- a/ffmpeg.c
+++ b/ffmpeg.c
@@ -1828,7 +1828,7 @@ static int transcode_subtitles(InputStream *ist, AVPacket *pkt, int *got_output)
     sub2video_update(ist, &subtitle);
 
     if (!subtitle.num_rects)
-        return ret;
+        goto out;
 
     for (i = 0; i < nb_output_streams; i++) {
         OutputStream *ost = output_streams[i];
@@ -1839,6 +1839,7 @@ static int transcode_subtitles(InputStream *ist, AVPacket *pkt, int *got_output)
         do_subtitle_out(output_files[ost->file_index]->ctx, ost, ist, &subtitle);
     }
 
+out:
     avsubtitle_free(&subtitle);
     return ret;
 }