lkml.org 
[lkml]   [2022]   [Jun]   [25]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [PATCH v4 2/5] perf tools riscv: Add support for get_cpuid_str function
Hello Arnaldo!

On Fri, 24 Jun 2022 13:32:20 -0300
Arnaldo Carvalho de Melo <acme@kernel.org> wrote:

> > + if (mimpid)
> > + free(mimpid);
>
> just use:
>
>
> free(mvendorid);
> free(marchid);
> free(mimpid);
>
> fewer lines, free() accepts NULL.
>
> > +
> > + return cpuid;
> > +}
> > +
> > +int get_cpuid(char *buffer, size_t sz)
> > +{
> > + char *cpuid = _get_cpuid();
> > +
> > + if (sz < strlen(cpuid)) {
> > + free(cpuid);
> > + return -EINVAL;
> > + }
> > +
> > + scnprintf(buffer, sz, "%s", cpuid);
>
> You're leaking cpuid here.

Agree with both.

Thank you for pointing it out.

>
> > + return 0;
> > +}
> > +
> > +char *
> > +get_cpuid_str(struct perf_pmu *pmu __maybe_unused)
> > +{
> > + return _get_cpuid();
> > +}
> > --
> > 2.35.1
>

\
 
 \ /
  Last update: 2022-06-25 07:29    [W:0.077 / U:1.688 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site