Handle error
diff --git a/Python/codecs.c b/Python/codecs.c
index 3aa1f38..464fffc 100644
--- a/Python/codecs.c
+++ b/Python/codecs.c
@@ -167,7 +167,10 @@
     }
 
     /* Cache and return the result */
-    PyDict_SetItem(interp->codec_search_cache, v, result);
+    if (PyDict_SetItem(interp->codec_search_cache, v, result) < 0) {
+	Py_DECREF(result);
+	goto onError;
+    }
     Py_DECREF(args);
     return result;