]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
zramctl: fix typo and memory leak
authorKarel Zak <kzak@redhat.com>
Fri, 6 Dec 2024 09:52:00 +0000 (10:52 +0100)
committerKarel Zak <kzak@redhat.com>
Fri, 6 Dec 2024 09:52:00 +0000 (10:52 +0100)
Signed-off-by: Karel Zak <kzak@redhat.com>
sys-utils/zramctl.c

index 335db01ba1c0a1335c1451ea5ba335a647b5a866..75fdfa33424ccc51d9181304a3cce47699ca78d4 100644 (file)
@@ -349,7 +349,6 @@ static int get_mm_stat(struct zram *z,
 {
        struct path_cxt *sysfs;
        const char *name;
-       char *str = NULL;
        uint64_t num;
 
        assert(idx < ARRAY_SIZE(mm_stat_names));
@@ -361,6 +360,7 @@ static int get_mm_stat(struct zram *z,
 
        /* Linux >= 4.1 uses /sys/block/zram<id>/mm_stat */
        if (!z->mm_stat && !z->mm_stat_probed) {
+               char *str = NULL;
                if (ul_path_read_string(sysfs, &str, "mm_stat") > 0 && str) {
                        z->mm_stat = strv_split(str, " ");
 
@@ -390,7 +390,7 @@ static int get_mm_stat(struct zram *z,
        /* Linux < 4.1 uses /sys/block/zram<id>/<attrname> */
        name = mm_stat_names[idx];
        if (re_str && bytes)
-               ul_path_read_string(sysfs, &str, name);
+               ul_path_read_string(sysfs, re_str, name);
 
        if ((re_str && !bytes) || re_num) {
                int rc = ul_path_read_u64(sysfs, &num, name);