[sword-devel] swld.cpp at line 111 - is this a bug?

Jaak Ristioja jaak at ristioja.ee
Wed Oct 12 00:22:30 MST 2016


On 12.10.2016 10:02, Manfred Bergmann wrote:
> 
>> Am 12.10.2016 um 08:57 schrieb Jaak Ristioja <jaak at ristioja.ee>:
>>
>> On 12.10.2016 09:37, Manfred Bergmann wrote:
>>>> On 12.10.2016 01:08, TS wrote:
>>>>> Xcode was warning me that in PocketSword's Sword framework, swld.cpp at
>>>>> line 111 with
>>>>>
>>>>> "delete buf;"
>>>>> may be wrong and it should perhaps be
>>>>>
>>>>> "delete[] buf;"
>>>>> instead. Is this correct? I looked at the code and I think Xcode is
>>>>> correct in that the variable is an array and needs the brackets to
>>>>> delete properly.
>>>>
>>>> Yes, Xcode has it correct. It should be `delete[] buf;`. This was also
>>>> fixed in Sword++ in March.
>>>
>>> Despite the warning, would but not be deleted completely?
>>
>> It is undefined behavior, as stated by §3.7.4.2.3 in C++11. However, the
>> C++ draft at https://github.com/cplusplus/draft doesn't have this
>> wording since e51a2152 [1] for some reason.
>>
> 
> Yeah, don’t get me wrong. It should be corrected.
> But is it indeed a memory leak or does the runtime still collect and destroy all array elements?
> Depends on the runtime probably.

It is undefined behavior (see http://stackoverflow.com/q/2397984/3919155
). So as far as the C++ standard is concerned, this might yield
different behavior depending on the toolchain, the runtime, the
environment or the phase of the moon... There are also no defined bounds
to what may happen: it may leak, crash, hang, corrupt memory, whatever...

J




More information about the sword-devel mailing list