<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Wed, Feb 11, 2015 at 12:30 PM, Francisco Jerez <span dir="ltr"><<a href="mailto:currojerez@riseup.net" target="_blank">currojerez@riseup.net</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span class="">Matt Turner <<a href="mailto:mattst88@gmail.com">mattst88@gmail.com</a>> writes:<br>
<br>
> On Wed, Feb 11, 2015 at 9:16 AM, Francisco Jerez <<a href="mailto:currojerez@riseup.net">currojerez@riseup.net</a>> wrote:<br>
>> Matt Turner <<a href="mailto:mattst88@gmail.com">mattst88@gmail.com</a>> writes:<br>
>><br>
>>> On Wed, Feb 11, 2015 at 6:37 AM, Juha-Pekka Heikkila<br>
>>> <<a href="mailto:juhapekka.heikkila@gmail.com">juhapekka.heikkila@gmail.com</a>> wrote:<br>
>>>> There is no error path available thus instead of giving<br>
>>>> realloc possibility to fail use new which will never<br>
>>>> return null pointer and throws bad_alloc on failure.<br>
>>><br>
>>> The problem was that we weren't checking if realloc failed.<br>
>>><br>
>>> Why is the solution to change from malloc/free to new/delete?<br>
>><br>
>> The new operator is guaranteed not to return NULL by the C++ standard.<br>
>> Aside from that Juha-Pekka's code seems more idiomatic to me than<br>
>> calling realloc() from a C++ source file, but that might just be a<br>
>> matter of taste.<br>
><br>
> But new will throw an exception if it fails, right? Presumably under<br>
> the same conditions as malloc/realloc returning NULL (i.e., being out<br>
> of address space).<br>
<br>
</span>Yeah, so this patch doesn't really handle the out of memory condition.<br>
According to Juha-Pekka it silences a Klocwork warning and IMHO it<br>
improves code-style slightly. But, sure, if it actually happens it's<br>
just trading one kind of failure for another.<br></blockquote><div><br></div><div>The fact of the matter is that we don't handle exceptions either so we get a crash either way. It's just the difference between a segfault or an unhandled exception. Also, for whatever it's worth, in the case where realloc can expand in-place, the realloc call will be faster because we won't have to do a memcpy. <br></div></div></div></div>