Browse Source

fix rc leak

blueloveTH 1 năm trước cách đây
mục cha
commit
026171e753
1 tập tin đã thay đổi với 6 bổ sung1 xóa
  1. 6 1
      include/pocketpy/common/refcount.h

+ 6 - 1
include/pocketpy/common/refcount.h

@@ -11,7 +11,12 @@ typedef struct RefCounted {
 } RefCounted;
 
 #define PK_INCREF(obj) (obj)->rc.count++
-#define PK_DECREF(obj) if (--(obj)->rc.count == 0) (obj)->rc.dtor(obj)
+#define PK_DECREF(obj) do { \
+    if(--(obj)->rc.count == 0) { \
+        (obj)->rc.dtor(obj); \
+        free(obj); \
+    } \
+} while(0)
 
 #ifdef __cplusplus
 }