[PATCH v2 3/5] tools/cpu/nios2/ptf.c: Fix leak of memory pointed to by new_prefix

Martin Galvan martin.galvan at tallertechnologies.com
Thu Sep 3 17:05:37 UTC 2015


On Thu, Sep 3, 2015 at 1:20 PM, Joel Sherrill <joel.sherrill at oarcorp.com> wrote:
> Am I misreading this or did the formatting change?
>
> It looks like the indentation on the "+" lines is different

Indeed :) Now the '+' lines are executed only if new_prefix != NULL
(new_prefix being the result of malloc). The resulting code looks like
this:

new_prefix = (char *)malloc(new_prefix_len);
if (new_prefix != NULL)
{
  strcpy(new_prefix, prefix);
  strcat(new_prefix, leaf->name);
  if(leaf->value != NULL && leaf->value[0] != 0)
  {
    strcat(new_prefix, ":");
    strcat(new_prefix, leaf->value);
  };
  strcat(new_prefix, "/");
  fputs(new_prefix, s);
  fputs("\n", s);
  ptf_printf(s, leaf->sub, new_prefix);
  free(new_prefix);
}



More information about the devel mailing list