]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
perf tests: use strdup() in "Object code reading"
authorJames Clark <james.clark@linaro.org>
Wed, 8 Oct 2025 12:42:00 +0000 (13:42 +0100)
committerNamhyung Kim <namhyung@kernel.org>
Mon, 13 Oct 2025 08:58:51 +0000 (01:58 -0700)
Use strdup() instead of fixed PATH_MAX buffer for storing paths to not
waste memory.

Suggested-by: Ian Rogers <irogers@google.com>
Reviewed-by: Ian Rogers <irogers@google.com>
Signed-off-by: James Clark <james.clark@linaro.org>
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
tools/perf/tests/code-reading.c

index 4c9fbf6965c4ad610be8f15803b3f9adbfce2067..1acb12b1a2eb31d3791978f82dac3b4bbc5fdf8b 100644 (file)
@@ -43,7 +43,7 @@
 struct tested_section {
        struct rb_node rb_node;
        u64 addr;
-       char path[PATH_MAX];
+       char *path;
 };
 
 static bool tested_code_insert_or_exists(const char *path, u64 addr,
@@ -79,7 +79,11 @@ static bool tested_code_insert_or_exists(const char *path, u64 addr,
                return true;
 
        data->addr = addr;
-       strlcpy(data->path, path, sizeof(data->path));
+       data->path = strdup(path);
+       if (!data->path) {
+               free(data);
+               return true;
+       }
        rb_link_node(&data->rb_node, parent, node);
        rb_insert_color(&data->rb_node, tested_sections);
        return false;
@@ -94,6 +98,7 @@ static void tested_sections__free(struct rb_root *root)
                                                     rb_node);
 
                rb_erase(node, root);
+               free(ts->path);
                free(ts);
        }
 }