perf tests: use strdup() in "Object code reading"
James Clark
reviewerPATCH v2 1/1 perf tests: use strdup() in "Object code reading"
Use strdup() instead of fixed PATH_MAX buffer for storing paths to not waste memory.
Suggested-by Ian Rogers <[email protected]>
Reviewed-by Ian Rogers <[email protected]>
Signed-off-by James Clark <[email protected]>
---
Applies on top of: https://lore.kernel.org/linux-perf-users/CAP-5=fV1N-j+f4GBFnDWsmoMZcz_k0U=nu1A7NZz-g4gzCH4KA@mail.gmail.com/T/#t
Changes since v1: handle strdup() failure
tools/perf/tests/code-reading.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-)
tools/perf/tests/code-reading.c +7 -2
@@ -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); } }
Signature · 1 line
2.34.1
Quoted 6 lines · James Clark
Use
strdup()instead of fixedPATH_MAXbuffer for storing paths to not waste memory.Suggested-by Ian Rogers <[email protected]>Reviewed-by Ian Rogers <[email protected]>Signed-off-by James Clark <[email protected]>
Applied to perf-tools-next, thanks!
Best regards,
Namhyung