6c61f8
diff --git a/src/dec/idec_dec.c b/src/dec/idec_dec.c
6c61f8
index a371ed7..258d15b 100644
6c61f8
--- a/src/dec/idec_dec.c
6c61f8
+++ b/src/dec/idec_dec.c
6c61f8
6c61f8
@@ -283,10 +283,8 @@
6c61f8
 
6c61f8
 static VP8StatusCode IDecError(WebPIDecoder* const idec, VP8StatusCode error) {
6c61f8
   if (idec->state_ == STATE_VP8_DATA) {
6c61f8
-    VP8Io* const io = &idec->io_;
6c61f8
-    if (io->teardown != NULL) {
6c61f8
-      io->teardown(io);
6c61f8
-    }
6c61f8
+    // Synchronize the thread, clean-up and check for errors.
6c61f8
+    VP8ExitCritical((VP8Decoder*)idec->dec_, &idec->io_);
6c61f8
   }
6c61f8
   idec->state_ = STATE_ERROR;
6c61f8
   return error;
6c61f8