Skip to content

Commit

Permalink
ramspeed:Fix memleak due to double malloc.
Browse files Browse the repository at this point in the history
  if (allocate_rw_address)
    {
      info->dest = malloc(info->size);
      info->src = malloc(info->size);
    }
  if ((info->dest == NULL && !info->allocate_rw_address) || info->size == 0)
    {
      printf(RAMSPEED_PREFIX "Missing required arguments\n");
      goto out;
    }
  else
    {
      /* We need to automatically apply for memory */
      printf(RAMSPEED_PREFIX "Allocate RW buffers on heap\n");
      info->dest = malloc(info->size);
      if (info->dest == NULL)
        {
          printf(RAMSPEED_PREFIX "Dest Alloc Memory Failed!\n");
          goto out;
        }
      info->src = malloc(info->size);
      if (info->src == NULL)
        {
          printf(RAMSPEED_PREFIX "Src Alloc Memory Failed!\n");
          goto out;
        }
    }

Signed-off-by: chenrun1 <[email protected]>
  • Loading branch information
crafcat7 authored and xiaoxiang781216 committed Aug 8, 2024
1 parent e047828 commit 875f2fc
Showing 1 changed file with 0 additions and 16 deletions.
16 changes: 0 additions & 16 deletions benchmarks/ramspeed/ramspeed_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -187,22 +187,6 @@ static void parse_commandline(int argc, FAR char **argv,
}
}

if (info->allocate_rw_address)
{
info->dest = malloc(info->size);
if (info->dest == NULL)
{
printf(RAMSPEED_PREFIX "Dest Alloc Memory Failed!\n");
}

info->src = malloc(info->size);
if (info->src == NULL)
{
free(info->dest);
printf(RAMSPEED_PREFIX "Src Alloc Memory Failed!\n");
}
}

if ((info->dest == NULL && !info->allocate_rw_address) || info->size == 0)
{
printf(RAMSPEED_PREFIX "Missing required arguments\n");
Expand Down

0 comments on commit 875f2fc

Please sign in to comment.