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

Joel Sherrill joel.sherrill at oarcorp.com
Thu Sep 3 16:20:16 UTC 2015


Am I misreading this or did the formatting change?

It looks like the indentation on the "+" lines is different

On 9/2/2015 4:54 PM, Martin Galvan wrote:
> Updates #2405.
> ---
>   tools/cpu/nios2/ptf.c | 24 ++++++++++++++----------
>   1 file changed, 14 insertions(+), 10 deletions(-)
>
> diff --git a/tools/cpu/nios2/ptf.c b/tools/cpu/nios2/ptf.c
> index 7a31c11..07d6183 100644
> --- a/tools/cpu/nios2/ptf.c
> +++ b/tools/cpu/nios2/ptf.c
> @@ -567,17 +567,21 @@ void ptf_printf(FILE *s, struct ptf *tree, char *prefix)
>             new_prefix_len += strlen(leaf->value) + 1;
>           };
>           new_prefix = (char *)malloc(new_prefix_len);
> -        strcpy(new_prefix, prefix);
> -        strcat(new_prefix, leaf->name);
> -        if(leaf->value != NULL && leaf->value[0] != 0)
> +        if (new_prefix != NULL)
>           {
> -          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);
> +          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);
> +        }
>           break;
>         };
>
>

-- 
Joel Sherrill, Ph.D.             Director of Research & Development
joel.sherrill at OARcorp.com        On-Line Applications Research
Ask me about RTEMS: a free RTOS  Huntsville AL 35805
Support Available                (256) 722-9985


More information about the devel mailing list