From b7894f10ca631e5b66aeb0c5fd7db3a9d9d5b39c Mon Sep 17 00:00:00 2001 From: Renge Date: Fri, 6 May 2022 14:53:13 -0400 Subject: [PATCH] fix: double free when ref < 0 --- hw5/src/tu.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/hw5/src/tu.c b/hw5/src/tu.c index 846ebc8..ccb7786 100644 --- a/hw5/src/tu.c +++ b/hw5/src/tu.c @@ -92,7 +92,7 @@ void tu_unref(TU *tu, char *reason) { pthread_mutex_lock(&tu->mutex); // debug(reason); tu->ref --; - if (tu->ref <= 0) + if (tu->ref == 0) tu_destroy(tu); else pthread_mutex_unlock(&tu->mutex); @@ -419,7 +419,7 @@ int tu_hangup(TU *tu) { tu->chat_TU = NULL; tu->ref --; tu->chat_locked = 0; - if (tu->ref <= 0) + if (tu->ref == 0) tu_destroy(tu); else pthread_mutex_unlock(&tu->mutex); @@ -456,7 +456,7 @@ int tu_hangup(TU *tu) { tu->chat_TU = NULL; tu->ref --; tu->chat_locked = 0; - if (tu->ref <= 0) + if (tu->ref == 0) tu_destroy(tu); else pthread_mutex_unlock(&tu->mutex);