]> git.ipfire.org Git - thirdparty/knot-resolver.git/commitdiff
contrib/cleanup: loosen type-checking in auto_free
authorVladimír Čunát <vladimir.cunat@nic.cz>
Mon, 30 Nov 2020 06:39:24 +0000 (07:39 +0100)
committerTomas Krizek <tomas.krizek@nic.cz>
Tue, 8 Dec 2020 14:35:00 +0000 (15:35 +0100)
- advantage:    `auto_free anyType *foo;` works (for anyType != char)
- disadvantage: `auto_free anyType bar;` is also accepted,
  though I expect such problems will be relatively easy to debug.

contrib/cleanup.h

index 1a51aad383271a50134fb338c40f68763c8e32f8..7d6cdbedc1aa6e09e4fb28b9be4728ddfe923628 100644 (file)
@@ -11,8 +11,8 @@
 #include <stdlib.h>
 
 #define auto_free __attribute__((cleanup(_cleanup_free)))
-static inline void _cleanup_free(char **p) {
-       free(*p);
+static inline void _cleanup_free(const void *p) {
+       free(*(char **)p);
 }
 #define auto_close __attribute__((cleanup(_cleanup_close)))
 static inline void _cleanup_close(int *p) {