8007606: Handle realloc() failure in unix/native/libnet/net_util_md.c correctly
authorigerasim
Wed, 16 Jan 2019 10:12:58 -0800
changeset 53349 d3aa93570779
parent 53348 331ba84b1e36
child 53350 a47b8125b7cc
8007606: Handle realloc() failure in unix/native/libnet/net_util_md.c correctly Reviewed-by: clanger, mbaesken
src/java.base/unix/native/libnet/net_util_md.c
--- a/src/java.base/unix/native/libnet/net_util_md.c	Wed Jan 09 19:05:05 2019 -0500
+++ b/src/java.base/unix/native/libnet/net_util_md.c	Wed Jan 16 10:12:58 2019 -0800
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1997, 2018, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 2019, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -647,6 +647,7 @@
     unsigned char staddr [16];
     char ifname [33];
     struct localinterface *lif=0;
+    struct localinterface *localifsTemp;
     int index, x1, x2, x3;
     unsigned int u0,u1,u2,u3,u4,u5,u6,u7,u8,u9,ua,ub,uc,ud,ue,uf;
 
@@ -675,13 +676,17 @@
         staddr[15] = (unsigned char)uf;
         nifs ++;
         if (nifs > localifsSize) {
-            localifs = (struct localinterface *) realloc (
+            localifsTemp = (struct localinterface *) realloc(
                         localifs, sizeof (struct localinterface)* (localifsSize+5));
-            if (localifs == 0) {
+            if (localifsTemp == 0) {
+                free(localifs);
+                localifs = 0;
+                localifsSize = 0;
                 nifs = 0;
-                fclose (f);
+                fclose(f);
                 return;
             }
+            localifs = localifsTemp;
             lif = localifs + localifsSize;
             localifsSize += 5;
         } else {