RFR 8007606 : Handle realloc() failure in unix/native/libnet/net_util_md.c correctly

Baesken, Matthias matthias.baesken at sap.com
Fri Jan 11 12:54:40 UTC 2019


(and btw.    There seem to  be a few other places in the coding   where  the realloc return  value is not checked , see for example :


jdk/src/hotspot/share/adlc/forms.cpp

50void   NameList::addName(const char *name) {
51  if (_cur == _max) _names =(const char**)realloc(_names,(_max *=2)*sizeof(char*));
52  _names[_cur++] = name;
53}


jdk/src/java.base/share/native/libjimage/imageFile.cpp

225// Add a new image entry to the table.
226void ImageFileReaderTable::add(ImageFileReader* image) {
227    if (_count == _max) {
228        _max += _growth;
229        _table = static_cast<ImageFileReader**>(realloc(_table, _max * sizeof(ImageFileReader*)));
230    }
231    _table[_count++] = image;
232}


 However I think adjustments of those cod parts is out of scope  of  8007606  .


Best regards, Matthias


> -----Original Message-----
> From: Baesken, Matthias
> Sent: Freitag, 11. Januar 2019 13:43
> To: net-dev at openjdk.java.net
> Subject: Re: RFR 8007606 : Handle realloc() failure in
> unix/native/libnet/net_util_md.c correctly
> 
> Hi Ivan,
> 
> Shouldn't you reset    localifsSize to 0   in case of  the early return ?  The
> comment says  localifsSize is the size of the array so the size of the array is 0
> again after freeing.
> 
> 
> 637 static struct localinterface *localifs = 0;
>  638 static int localifsSize = 0;    /* size of array */
>  639 static int nifs = 0;            /* number of entries used in array */
> 
>    ...
> 
> 679             if (localifsTemp == 0) {
>  680                 free(localifs);
>  681                 localifs = 0;
>  682                 nifs = 0;
>  683                 fclose(f);
>  684                 return;
>  685             }
> 
> 
> 
> 
> Best regards, Matthias
> 
> 
> 
> > Date: Thu, 10 Jan 2019 20:29:08 -0800
> > From: Ivan Gerasimov <ivan.gerasimov at oracle.com>
> > To: "net-dev at openjdk.java.net" <net-dev at openjdk.java.net>
> > Subject: RFR 8007606 : Handle realloc() failure in
> > 	unix/native/libnet/net_util_md.c correctly
> > Message-ID: <3dc3c26b-fea7-2538-2c7a-bfa623f2fc86 at oracle.com>
> > Content-Type: text/plain; charset=utf-8; format=flowed
> >
> > Hello!
> >
> > This seems to be the last use of realloc() without proper handling of a
> > failure.
> >
> > Would you please help review a trivial fix?
> >
> > BUGURL: https://bugs.openjdk.java.net/browse/JDK-8007606
> > WEBREV: http://cr.openjdk.java.net/~igerasim/8007606/00/webrev/
> >
> > Thanks in advance!
> >
> > --
> > With kind regards,
> > Ivan Gerasimov
> >
> >



More information about the net-dev mailing list