Changeset: eff47eb13d79 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/eff47eb13d79
Modified Files:
common/stream/stream.c
Branch: Jul2021
Log Message:
Manually deallocate the main thread's error buffer
The destructor registered with pthread_setspecific() does not
always get called for the main thread so we clear it using an
atexit hook.
diffs (29 lines):
diff --git a/common/stream/stream.c b/common/stream/stream.c
--- a/common/stream/stream.c
+++ b/common/stream/stream.c
@@ -72,11 +72,25 @@ static struct tl_error_buf *get_tl_error
static pthread_key_t tl_error_key;
+static void
+clear_main_tl_error_buf(void)
+{
+ void *p = pthread_getspecific(tl_error_key);
+ if (p != NULL) {
+ pthread_setspecific(tl_error_key, NULL);
+ free(p);
+ }
+}
+
static int
tl_error_init(void)
{
if (pthread_key_create(&tl_error_key, free) != 0)
return -1;
+ // Turns out the destructor registered with pthread_key_create() does
not
+ // always run for the main thread. This atexit hook clears the main
thread's
+ // error buffer to avoid this being reported as a memory leak.
+ atexit(clear_main_tl_error_buf);
return 0;
}
_______________________________________________
checkin-list mailing list -- [email protected]
To unsubscribe send an email to [email protected]