Changeset c83bad2f in rtems


Ignore:
Timestamp:
Sep 2, 2015, 9:54:25 PM (4 years ago)
Author:
Martin Galvan <martin.galvan@…>
Branches:
master
Children:
9147a82
Parents:
17f71fc
git-author:
Martin Galvan <martin.galvan@…> (09/02/15 21:54:25)
git-committer:
Joel Sherrill <joel.sherrill@…> (09/03/15 16:28:10)
Message:

cpukit/libnetworking/rtems/rtems_dhcp.c: Fix leak on realloc failure for dhcp_hostname.

Closes #2405.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • cpukit/libnetworking/rtems/rtems_dhcp.c

    r17f71fc rc83bad2f  
    395395          len = MAXHOSTNAMELEN-1;
    396396        }
    397         if (sethostname (p, len) < 0)
     397        if (sethostname (p, len) < 0) {
    398398          printf ("dhcpc: can't set host name");
     399        }
    399400        if (dhcp_hostname != NULL)
    400401        {
    401           dhcp_hostname = realloc (dhcp_hostname, len);
    402           strncpy (dhcp_hostname, p, len);
    403         }
    404         else
     402          char *tmp = realloc (dhcp_hostname, len);
     403          if (tmp != NULL) {
     404            dhcp_hostname = tmp;
     405            strncpy (dhcp_hostname, p, len);
     406          } else {  /* realloc failed */
     407            printf ("dhcpc: realloc failed (%s:%d)", __FILE__, __LINE__);
     408            free (dhcp_hostname);
     409            dhcp_hostname = NULL;
     410          }
     411        } else { /* dhcp_hostname == NULL */
    405412          dhcp_hostname = strndup (p, len);
     413        }
    406414        break;
    407415
Note: See TracChangeset for help on using the changeset viewer.