1
0
mirror of https://github.com/systemd/systemd.git synced 2024-10-30 06:25:37 +03:00

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.
This commit is contained in:
Lennart Poettering 2021-08-10 14:36:00 +02:00 committed by Yu Watanabe
parent 76f226d71b
commit 5afcf89ca2
2 changed files with 8 additions and 6 deletions

View File

@ -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) \
({ \

View File

@ -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;
}
}