summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMartin Galvan <martin.galvan@tallertechnologies.com>2015-09-02 16:54:25 -0500
committerJoel Sherrill <joel.sherrill@oarcorp.com>2015-09-03 11:27:48 -0500
commitc62129c5bcaf2b10baf7d3e1b856c81e343c4b5b (patch)
treef7f175eddb381f99306ac269017c623fa245f268
parenttools/cpu/nios2/memory.c: Fix uninitialized use of variable memory (diff)
downloadrtems-c62129c5bcaf2b10baf7d3e1b856c81e343c4b5b.tar.bz2
cpukit/libnetworking/rtems/rtems_dhcp.c: Fix leak on realloc failure for dhcp_hostname.
Closes #2405.
-rw-r--r--cpukit/libnetworking/rtems/rtems_dhcp.c18
1 files changed, 13 insertions, 5 deletions
diff --git a/cpukit/libnetworking/rtems/rtems_dhcp.c b/cpukit/libnetworking/rtems/rtems_dhcp.c
index c938ee028f..87be238ddb 100644
--- a/cpukit/libnetworking/rtems/rtems_dhcp.c
+++ b/cpukit/libnetworking/rtems/rtems_dhcp.c
@@ -394,15 +394,23 @@ process_options (unsigned char *optbuf, int optbufSize)
printf ("dhcpc: hostname >= %d bytes\n", MAXHOSTNAMELEN);
len = MAXHOSTNAMELEN-1;
}
- if (sethostname (p, len) < 0)
+ if (sethostname (p, len) < 0) {
printf ("dhcpc: can't set host name");
+ }
if (dhcp_hostname != NULL)
{
- dhcp_hostname = realloc (dhcp_hostname, len);
- strncpy (dhcp_hostname, p, len);
- }
- else
+ char *tmp = realloc (dhcp_hostname, len);
+ if (tmp != NULL) {
+ dhcp_hostname = tmp;
+ strncpy (dhcp_hostname, p, len);
+ } else { /* realloc failed */
+ printf ("dhcpc: realloc failed (%s:%d)", __FILE__, __LINE__);
+ free (dhcp_hostname);
+ dhcp_hostname = NULL;
+ }
+ } else { /* dhcp_hostname == NULL */
dhcp_hostname = strndup (p, len);
+ }
break;
case 7: