From 026171e753fdd052f80a12e168a0d6a090c57b7b Mon Sep 17 00:00:00 2001 From: blueloveTH Date: Mon, 17 Jun 2024 12:18:28 +0800 Subject: [PATCH] fix rc leak --- include/pocketpy/common/refcount.h | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/include/pocketpy/common/refcount.h b/include/pocketpy/common/refcount.h index 15780bf8..8623cd39 100644 --- a/include/pocketpy/common/refcount.h +++ b/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 }