bpo-31787: Prevent refleaks when calling __init__() more than once (GH-3995)

(cherry picked from commit d019bc8319ea35e93bf4baa38098ff1b57cd3ee5)

Co-authored-by: Oren Milman <orenmn@gmail.com>
diff --git a/Objects/funcobject.c b/Objects/funcobject.c
index d376f9c..241685d 100644
--- a/Objects/funcobject.c
+++ b/Objects/funcobject.c
@@ -709,7 +709,7 @@
     if (!PyArg_UnpackTuple(args, "classmethod", 1, 1, &callable))
         return -1;
     Py_INCREF(callable);
-    cm->cm_callable = callable;
+    Py_XSETREF(cm->cm_callable, callable);
     return 0;
 }
 
@@ -890,7 +890,7 @@
     if (!PyArg_UnpackTuple(args, "staticmethod", 1, 1, &callable))
         return -1;
     Py_INCREF(callable);
-    sm->sm_callable = callable;
+    Py_XSETREF(sm->sm_callable, callable);
     return 0;
 }