Code

utils error: Make sure to destroy memory allocated for error information.
[sysdb.git] / src / utils / error.c
index 34213b319501a7ca13e1d5d10843c6ceb295f4fe..08a77f1c40b9007d9e05dd365dc9a6b07f5e15c3 100644 (file)
@@ -33,6 +33,8 @@
 #include <stdio.h>
 #include <string.h>
 
+#include <stdlib.h>
+
 /*
  * private data types
  */
@@ -57,13 +59,21 @@ static _Bool         error_ctx_key_initialized = 0;
  * private helper functions
  */
 
+static void
+sdb_error_ctx_destructor(void *ctx)
+{
+       if (! ctx)
+               return;
+       free(ctx);
+} /* sdb_error_ctx_destructor */
+
 static void
 sdb_error_ctx_init(void)
 {
        if (error_ctx_key_initialized)
                return;
 
-       pthread_key_create(&error_ctx_key, NULL);
+       pthread_key_create(&error_ctx_key, sdb_error_ctx_destructor);
        error_ctx_key_initialized = 1;
 } /* sdb_error_init */