summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2021-08-10 14:36:00 +0200
committerYu Watanabe <watanabe.yu+github@gmail.com>2021-08-11 04:47:10 +0900
commit5afcf89ca29b518eb2fa244b015afc2708f77e1d (patch)
tree9eab9ddad63b6d7aa0592d3f43e12dbae70b08cb /src
parent76f226d71b9d8d36eb4e61285e80527637299fac (diff)
downloadsystemd-5afcf89ca29b518eb2fa244b015afc2708f77e1d.tar.gz
alloc-util: make mfree() typesafe
Make sure we return the same type as we accept. One incorrect use of mfree() is discovered and fixed this way.
Diffstat (limited to 'src')
-rw-r--r--src/basic/alloc-util.h9
-rw-r--r--src/resolve/resolved-dns-rr.c5
2 files changed, 8 insertions, 6 deletions
diff --git a/src/basic/alloc-util.h b/src/basic/alloc-util.h
index 0af425e491..e587fe79e7 100644
--- a/src/basic/alloc-util.h
+++ b/src/basic/alloc-util.h
@@ -44,10 +44,11 @@ typedef void (*free_func_t)(void *p);
#define malloc0(n) (calloc(1, (n) ?: 1))
-static inline void *mfree(void *memory) {
- free(memory);
- return NULL;
-}
+#define mfree(memory) \
+ ({ \
+ free(memory); \
+ (typeof(memory)) NULL; \
+ })
#define free_and_replace(a, b) \
({ \
diff --git a/src/resolve/resolved-dns-rr.c b/src/resolve/resolved-dns-rr.c
index 4a0327a19d..d98914e8b8 100644
--- a/src/resolve/resolved-dns-rr.c
+++ b/src/resolve/resolved-dns-rr.c
@@ -47,8 +47,8 @@ DnsResourceKey* dns_resource_key_new_redirect(const DnsResourceKey *key, const D
if (cname->key->type == DNS_TYPE_CNAME)
return dns_resource_key_new(key->class, key->type, cname->cname.name);
else {
+ _cleanup_free_ char *destination = NULL;
DnsResourceKey *k;
- char *destination = NULL;
r = dns_name_change_suffix(dns_resource_key_name(key), dns_resource_key_name(cname->key), cname->dname.name, &destination);
if (r < 0)
@@ -58,8 +58,9 @@ DnsResourceKey* dns_resource_key_new_redirect(const DnsResourceKey *key, const D
k = dns_resource_key_new_consume(key->class, key->type, destination);
if (!k)
- return mfree(destination);
+ return NULL;
+ TAKE_PTR(destination);
return k;
}
}