From: Yu Watanabe Date: Tue, 29 Sep 2020 20:40:14 +0000 (+0900) Subject: network: make prefix_free() and route_prefix_free() return NULL X-Git-Tag: v247-rc1~117^2~75 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=064dfb05f0c69800e731d1d2e8acbf09cac36136;p=thirdparty%2Fsystemd.git network: make prefix_free() and route_prefix_free() return NULL --- diff --git a/src/network/networkd-radv.c b/src/network/networkd-radv.c index 003a50b68b0..3382fa1f5a6 100644 --- a/src/network/networkd-radv.c +++ b/src/network/networkd-radv.c @@ -16,9 +16,9 @@ #include "string-table.h" #include "strv.h" -void prefix_free(Prefix *prefix) { +Prefix *prefix_free(Prefix *prefix) { if (!prefix) - return; + return NULL; if (prefix->network) { LIST_REMOVE(prefixes, prefix->network->static_prefixes, prefix); @@ -33,9 +33,11 @@ void prefix_free(Prefix *prefix) { network_config_section_free(prefix->section); sd_radv_prefix_unref(prefix->radv_prefix); - free(prefix); + return mfree(prefix); } +DEFINE_NETWORK_SECTION_FUNCTIONS(Prefix, prefix_free); + static int prefix_new(Prefix **ret) { _cleanup_(prefix_freep) Prefix *prefix = NULL; @@ -101,24 +103,9 @@ static int prefix_new_static(Network *network, const char *filename, return 0; } -static int route_prefix_new(RoutePrefix **ret) { - _cleanup_(route_prefix_freep) RoutePrefix *prefix = NULL; - - prefix = new0(RoutePrefix, 1); - if (!prefix) - return -ENOMEM; - - if (sd_radv_route_prefix_new(&prefix->radv_route_prefix) < 0) - return -ENOMEM; - - *ret = TAKE_PTR(prefix); - - return 0; -} - -void route_prefix_free(RoutePrefix *prefix) { +RoutePrefix *route_prefix_free(RoutePrefix *prefix) { if (!prefix) - return; + return NULL; if (prefix->network) { LIST_REMOVE(route_prefixes, prefix->network->static_route_prefixes, prefix); @@ -133,7 +120,24 @@ void route_prefix_free(RoutePrefix *prefix) { network_config_section_free(prefix->section); sd_radv_route_prefix_unref(prefix->radv_route_prefix); - free(prefix); + return mfree(prefix); +} + +DEFINE_NETWORK_SECTION_FUNCTIONS(RoutePrefix, route_prefix_free); + +static int route_prefix_new(RoutePrefix **ret) { + _cleanup_(route_prefix_freep) RoutePrefix *prefix = NULL; + + prefix = new0(RoutePrefix, 1); + if (!prefix) + return -ENOMEM; + + if (sd_radv_route_prefix_new(&prefix->radv_route_prefix) < 0) + return -ENOMEM; + + *ret = TAKE_PTR(prefix); + + return 0; } static int route_prefix_new_static(Network *network, const char *filename, diff --git a/src/network/networkd-radv.h b/src/network/networkd-radv.h index 496ef97adcf..7addf45e94b 100644 --- a/src/network/networkd-radv.h +++ b/src/network/networkd-radv.h @@ -42,13 +42,8 @@ struct RoutePrefix { LIST_FIELDS(RoutePrefix, route_prefixes); }; -void prefix_free(Prefix *prefix); - -DEFINE_NETWORK_SECTION_FUNCTIONS(Prefix, prefix_free); - -void route_prefix_free(RoutePrefix *prefix); - -DEFINE_NETWORK_SECTION_FUNCTIONS(RoutePrefix, route_prefix_free); +Prefix *prefix_free(Prefix *prefix); +RoutePrefix *route_prefix_free(RoutePrefix *prefix); int radv_emit_dns(Link *link); int radv_configure(Link *link);