]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
network: make prefix_free() and route_prefix_free() return NULL
authorYu Watanabe <watanabe.yu+github@gmail.com>
Tue, 29 Sep 2020 20:40:14 +0000 (05:40 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Tue, 6 Oct 2020 17:44:42 +0000 (02:44 +0900)
src/network/networkd-radv.c
src/network/networkd-radv.h

index 003a50b68b06ff2c727c0772d73b754a22a6e9ee..3382fa1f5a68d4731117cb56ff33fbaec8a6d276 100644 (file)
@@ -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,
index 496ef97adcf6cca844e2a0b821138d39e78ae243..7addf45e94be09eab1ded4e6023602feb6bf8071 100644 (file)
@@ -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);