[RTEMS Project] #3570: Resource leak in flashdisk.c (CID 1439298)

RTEMS trac trac at rtems.org
Thu Oct 25 23:30:03 UTC 2018


#3570: Resource leak in flashdisk.c (CID 1439298)
-----------------------+-------------------------
 Reporter:  embeddedt  |       Owner:  (none)
     Type:  defect     |      Status:  new
 Priority:  normal     |   Milestone:  Indefinite
Component:  admin      |     Version:  6
 Severity:  normal     |  Resolution:
 Keywords:  Coverity   |  Blocked By:
 Blocking:             |
-----------------------+-------------------------

Comment (by embeddedt):

 Please use this information from Coverity:

 {{{
 2456
     2. alloc_fn: Storage is returned from allocation function calloc.
 [Note: The source code implementation of the function has been overridden
 by a builtin model.]
     3. var_assign: Assigning: fd = storage returned from
 calloc(rtems_flashdisk_configuration_size, 132U).
 2457  fd = calloc (rtems_flashdisk_configuration_size, sizeof (*fd));
     4. Condition !fd, taking false branch.
 2458  if (!fd)
 2459    return RTEMS_NO_MEMORY;
 }}}

 {{{
 2496    fd->devices = calloc (c->device_count, sizeof
 (rtems_fdisk_device_ctl));
 2497    if (!fd->devices)
     CID 1439298 (#1 of 2): Resource leak (RESOURCE_LEAK) [select issue]
 2498      return RTEMS_NO_MEMORY;
 }}}

 There are two places where my mentor noticed a potential leak but these
 would require further investigation. They are at lines 2568 and 2581.

 {{{
 2558    ret = rtems_fdisk_recover_block_mappings (fd);
 2559    if (ret)
 2560    {
 2561      unlink (name);
 2562      rtems_mutex_destroy (&fd->lock);
 2563      free (fd->copy_buffer);
 2564      free (fd->blocks);
 2565      free (fd->devices);
 2566      rtems_fdisk_error ("recovery of disk failed: %s (%d)",
 2567                         strerror (ret), ret);
 2568      return ret;
 2569    }
 2570
 2571    ret = rtems_fdisk_compact (fd);
 2572    if (ret)
 2573    {
 2574      unlink (name);
 2575      rtems_mutex_destroy (&fd->lock);
 2576      free (fd->copy_buffer);
 2577      free (fd->blocks);
 2578      free (fd->devices);
 2579      rtems_fdisk_error ("compacting of disk failed: %s (%d)",
 2580                         strerror (ret), ret);
 2581      return ret;
 2582    }
 }}}

--
Ticket URL: <http://devel.rtems.org/ticket/3570#comment:1>
RTEMS Project <http://www.rtems.org/>
RTEMS Project


More information about the bugs mailing list