Fix some memory leaks caused by buggy macros for reference counting

This commit is contained in:
Paul B Mahol 2022-07-24 01:26:49 +02:00 committed by pancake
parent cd15bdb1e8
commit b446f7ab47
2 changed files with 5 additions and 2 deletions

View File

@ -3283,6 +3283,9 @@ R_API void r_core_fini(RCore *c) {
r_core_task_scheduler_fini (&c->tasks);
c->rcmd = r_cmd_free (c->rcmd);
r_list_free (c->cmd_descriptors);
r_unref (c->print->config);
r_unref (c->anal->reg->config);
r_unref (c->anal->config);
r_anal_free (c->anal);
r_asm_free (c->rasm);
c->rasm = NULL;

View File

@ -758,10 +758,10 @@ typedef int RRef;
#define R_REF_NAME refcount
#define r_ref(x) ((x)->R_REF_NAME++, (x));
#define r_ref_set(x,y) do { if(x) { (x)->R_REF_NAME--; } (x)=(y); (x)->R_REF_NAME++;} while(0)
#define r_ref_init(x,y) (x)->R_REF_NAME = 1;(x)->free = (void *)(y)
// #define r_unref(x) { assert (x->R_REF_NAME > 0); if (!--(x->R_REF_NAME)) { x->free(x); } }
#define r_unref(x) { if (x->R_REF_NAME > 0 && !--(x->R_REF_NAME)) { x->free(x); } }
#define r_unref(x) { if ((x) != NULL && (x)->R_REF_NAME > 0 && !--((x)->R_REF_NAME)) { (x)->free(x); (x) = NULL; } }
#define r_ref_set(x,y) do { if ((x) != (y) && (x) != NULL) { r_unref(x); } (x)=(y); (y)->R_REF_NAME++; } while(0)
#define R_REF_TYPE RRef R_REF_NAME; void (*free)(void*)
#define R_REF_FUNCTIONS(s, n) \