]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
chmem: simplify have_mem_blk_zones()
authorKarel Zak <kzak@redhat.com>
Thu, 28 May 2026 08:54:33 +0000 (10:54 +0200)
committerKarel Zak <kzak@redhat.com>
Thu, 28 May 2026 08:54:33 +0000 (10:54 +0200)
Use ul_path_accessf() instead of manual ul_strconcat() + ul_path_access()
+ free(). This avoids a potential NULL dereference if ul_strconcat() fails
on memory allocation.

Signed-off-by: Karel Zak <kzak@redhat.com>
sys-utils/chmem.c

index 8a70d85eb94d3aac3bb8e5ee535cd3fe80ef14be..1034e854b9c4613f4b697415166e4cbbb2d20dde 100644 (file)
@@ -84,21 +84,11 @@ static const char *const zone_names[] = {
        [ZONE_DEVICE]   = "Device",
 };
 
-
 static int have_mem_blk_zones(struct path_cxt *pctx, const char *dirname)
 {
-       int rc = 0;
-       char *path = NULL;
-
        if (!pctx || !dirname)
                return -EINVAL;
-
-       path = ul_strconcat(dirname, "/valid_zones");
-       if (ul_path_access(pctx, F_OK, path) == 0)
-               rc = 1;
-
-       free(path);
-       return rc;
+       return ul_path_accessf(pctx, F_OK, "%s/valid_zones", dirname) == 0;
 }
 
 /*