]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
mount: use free_and_strdup() over plain strdup()
authorLennart Poettering <lennart@poettering.net>
Wed, 28 Nov 2018 13:40:56 +0000 (14:40 +0100)
committerLennart Poettering <lennart@poettering.net>
Fri, 7 Dec 2018 16:34:29 +0000 (17:34 +0100)
Let's initialize two fields with free_and_strdup() rather than directly
with strdup(). The fields should not be initialized so far, but it's
still nicer to be prepared for futzre code changes and always free
what's stored before replacing it.

src/core/mount.c

index a9f64eb39a0576011eacaf0b404a9e3dff6b818a..d19dce094473339ce2c2aff91539e4b299b13e5e 100644 (file)
@@ -1475,13 +1475,13 @@ static int mount_setup_new_unit(
         if (r < 0)
                 return r;
 
-        u->source_path = strdup("/proc/self/mountinfo");
-        MOUNT(u)->where = strdup(where);
-        if (!u->source_path || !MOUNT(u)->where)
-                return -ENOMEM;
+        r = free_and_strdup(&u->source_path, "/proc/self/mountinfo");
+        if (r < 0)
+                return r;
 
-        /* Make sure to initialize those fields before mount_is_extrinsic(). */
-        MOUNT(u)->from_proc_self_mountinfo = true;
+        r = free_and_strdup(&MOUNT(u)->where, where);
+        if (r < 0)
+                return r;
 
         r = update_parameters_proc_self_mount_info(MOUNT(u), what, options, fstype);
         if (r < 0)