From 1e5cb6456929de15be97ba7242b6f5b833d3b873 Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Thu, 22 Dec 2022 11:36:06 +0100 Subject: [PATCH] heimbase-atomics: fix heim_base_atomic_* on AIX The API looks like this on AIX: typedef int *atomic_p; int fetch_and_add(atomic_p addr, int value); The strange thing is that the xlc compiler ignores missing arguments by default. (It warns but doesn't fail to compile) As a result the value argument was just uninitialized memory, which means that the ref_cnt variable of struct heim_base, gets unpredictable values during heim_retain() and heim_release(), resulting in memory leaks. Signed-off-by: Stefan Metzmacher --- lib/base/heimbase-atomics.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/base/heimbase-atomics.h b/lib/base/heimbase-atomics.h index 702cca7c0..6401f60de 100644 --- a/lib/base/heimbase-atomics.h +++ b/lib/base/heimbase-atomics.h @@ -103,10 +103,10 @@ #define heim_base_atomic_barrier() __isync() -#define heim_base_atomic_inc(x) (fetch_and_add((atomic_p)(x)) + 1) -#define heim_base_atomic_dec(x) (fetch_and_add((atomic_p)(x)) - 1) -#define heim_base_atomic_integer_type unsigned int -#define heim_base_atomic_integer_max UINT_MAX +#define heim_base_atomic_inc(x) (fetch_and_add((atomic_p)(x), 1) + 1) +#define heim_base_atomic_dec(x) (fetch_and_add((atomic_p)(x), -1) - 1) +#define heim_base_atomic_integer_type int +#define heim_base_atomic_integer_max INT_MAX static inline void * heim_base_exchange_pointer(void *p, void *newval)