mirror of
https://github.com/systemd/systemd.git
synced 2024-12-23 21:35:11 +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:
parent
76f226d71b
commit
5afcf89ca2
@ -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) \
|
||||
({ \
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user