Avoid a PATH_MAX array in __daemon (the .data section) by dynamically
allocating the memory.
Signed-off-by: Ian Rogers <[email protected]>
---
tools/perf/builtin-daemon.c | 15 +++++++++++++--
1 file changed, 13 insertions(+), 2 deletions(-)
diff --git a/tools/perf/builtin-daemon.c b/tools/perf/builtin-daemon.c
index 34cbe3e959aa..adb5751c3ed0 100644
--- a/tools/perf/builtin-daemon.c
+++ b/tools/perf/builtin-daemon.c
@@ -90,7 +90,7 @@ struct daemon {
char *base;
struct list_head sessions;
FILE *out;
- char perf[PATH_MAX];
+ char *perf;
int signal_fd;
time_t start;
};
@@ -1490,6 +1490,15 @@ static int __cmd_ping(struct daemon *daemon, struct option parent_options[],
return send_cmd(daemon, &cmd);
}
+static char *set_perf_exe(void)
+{
+ char path[PATH_MAX];
+
+ perf_exe(path, sizeof(path));
+ __daemon.perf = strdup(path);
+ return __daemon.perf;
+}
+
int cmd_daemon(int argc, const char **argv)
{
struct option daemon_options[] = {
@@ -1503,7 +1512,9 @@ int cmd_daemon(int argc, const char **argv)
OPT_END()
};
- perf_exe(__daemon.perf, sizeof(__daemon.perf));
+ if (!set_perf_exe())
+ return -ENOMEM;
+
__daemon.out = stdout;
argc = parse_options(argc, argv, daemon_options, daemon_usage,
--
2.40.1.698.g37aff9b760-goog
On Thu, May 25, 2023 at 12:12 AM Ian Rogers <[email protected]> wrote:
>
> Avoid a PATH_MAX array in __daemon (the .data section) by dynamically
> allocating the memory.
>
> Signed-off-by: Ian Rogers <[email protected]>
> ---
> tools/perf/builtin-daemon.c | 15 +++++++++++++--
> 1 file changed, 13 insertions(+), 2 deletions(-)
>
> diff --git a/tools/perf/builtin-daemon.c b/tools/perf/builtin-daemon.c
> index 34cbe3e959aa..adb5751c3ed0 100644
> --- a/tools/perf/builtin-daemon.c
> +++ b/tools/perf/builtin-daemon.c
> @@ -90,7 +90,7 @@ struct daemon {
> char *base;
> struct list_head sessions;
> FILE *out;
> - char perf[PATH_MAX];
> + char *perf;
> int signal_fd;
> time_t start;
> };
> @@ -1490,6 +1490,15 @@ static int __cmd_ping(struct daemon *daemon, struct option parent_options[],
> return send_cmd(daemon, &cmd);
> }
>
> +static char *set_perf_exe(void)
> +{
> + char path[PATH_MAX];
> +
> + perf_exe(path, sizeof(path));
> + __daemon.perf = strdup(path);
> + return __daemon.perf;
Then you need to free it somewhere.
Thanks,
Namhyung
> +}
> +
> int cmd_daemon(int argc, const char **argv)
> {
> struct option daemon_options[] = {
> @@ -1503,7 +1512,9 @@ int cmd_daemon(int argc, const char **argv)
> OPT_END()
> };
>
> - perf_exe(__daemon.perf, sizeof(__daemon.perf));
> + if (!set_perf_exe())
> + return -ENOMEM;
> +
> __daemon.out = stdout;
>
> argc = parse_options(argc, argv, daemon_options, daemon_usage,
> --
> 2.40.1.698.g37aff9b760-goog
>
On Thu, May 25, 2023 at 12:17 PM Namhyung Kim <[email protected]> wrote:
>
> On Thu, May 25, 2023 at 12:12 AM Ian Rogers <[email protected]> wrote:
> >
> > Avoid a PATH_MAX array in __daemon (the .data section) by dynamically
> > allocating the memory.
> >
> > Signed-off-by: Ian Rogers <[email protected]>
> > ---
> > tools/perf/builtin-daemon.c | 15 +++++++++++++--
> > 1 file changed, 13 insertions(+), 2 deletions(-)
> >
> > diff --git a/tools/perf/builtin-daemon.c b/tools/perf/builtin-daemon.c
> > index 34cbe3e959aa..adb5751c3ed0 100644
> > --- a/tools/perf/builtin-daemon.c
> > +++ b/tools/perf/builtin-daemon.c
> > @@ -90,7 +90,7 @@ struct daemon {
> > char *base;
> > struct list_head sessions;
> > FILE *out;
> > - char perf[PATH_MAX];
> > + char *perf;
> > int signal_fd;
> > time_t start;
> > };
> > @@ -1490,6 +1490,15 @@ static int __cmd_ping(struct daemon *daemon, struct option parent_options[],
> > return send_cmd(daemon, &cmd);
> > }
> >
> > +static char *set_perf_exe(void)
> > +{
> > + char path[PATH_MAX];
> > +
> > + perf_exe(path, sizeof(path));
> > + __daemon.perf = strdup(path);
> > + return __daemon.perf;
>
> Then you need to free it somewhere.
For leak sanitizer, if an allocation is reachable from a global then
it isn't considered a leak. I'll address this in v2.
Thanks,
Ian
> Thanks,
> Namhyung
>
>
> > +}
> > +
> > int cmd_daemon(int argc, const char **argv)
> > {
> > struct option daemon_options[] = {
> > @@ -1503,7 +1512,9 @@ int cmd_daemon(int argc, const char **argv)
> > OPT_END()
> > };
> >
> > - perf_exe(__daemon.perf, sizeof(__daemon.perf));
> > + if (!set_perf_exe())
> > + return -ENOMEM;
> > +
> > __daemon.out = stdout;
> >
> > argc = parse_options(argc, argv, daemon_options, daemon_usage,
> > --
> > 2.40.1.698.g37aff9b760-goog
> >