]> granicus.if.org Git - libevent/commitdiff
test: fix debug locks in case new lock gots old address
authorAzat Khuzhin <azat@libevent.org>
Sun, 12 Feb 2023 07:34:52 +0000 (08:34 +0100)
committerAzat Khuzhin <azat@libevent.org>
Sun, 12 Feb 2023 07:49:47 +0000 (08:49 +0100)
Refs: #1407

test/regress_bufferevent.c

index 83cb804b0093506399ada2a607331e31cb29ad14..0775a523415c977082ce9f8e91ee53da43fce38d 100644 (file)
@@ -254,10 +254,18 @@ static lock_wrapper *lu_find(void *lock_)
 static void *trace_lock_alloc(unsigned locktype)
 {
        void *lock;
+       lock_wrapper *existing_lock;
+
+       lock = lu_base.cbs.alloc(locktype);
+       existing_lock = lu_find(lock);
+       if (existing_lock) {
+               existing_lock->status = ALLOC;
+               return lock;
+       }
+
        ++lu_base.nr_locks;
        lu_base.locks = realloc(lu_base.locks,
                sizeof(lock_wrapper) * lu_base.nr_locks);
-       lock = lu_base.cbs.alloc(locktype);
        lu_base.locks[lu_base.nr_locks - 1] = (lock_wrapper){ lock, ALLOC, 0 };
        return lock;
 }