On 01/21/2018 02:07 PM, Ian Collins wrote:
> On 01/22/2018 07:39 AM, James Kuyper wrote:
>> I know a lot about C++98 in theory, and a little bit about more recent
>> versions of the language, but have relatively little practical
>> experience with it: For several years now, one of my responsibilities
>> has been the maintenance of several C++ programs linked to a set of C++
>> libraries, poorly designed and no documentation. They're written to
>> C++2003. I've never had a problem working with this code due to my lack
>> of C++ experience - all of my problems have been due to the poor design
>> and the lack of documentation.
>> However, I've run into a problem that is new to me, and I wasn't sure
>> how to investigate further. One of these programs aborts under certain
>> circumstances during an attempt to execute a delete expression.
>
> The key is probably how it aborts.
It exits with a unix status of 34304=0x8600, indicating abnormal
termination by signal number of 6, which is SIGABRT. When I said
"abort", I was being very specific.
> Is there an unhandled exception?
>
> Is there a memory access violation?
There's no indication of either possibility.
> Can you trap it in a debugger?
I'm just starting to investigate this problem, and am learning things
about the program that I hadn't previously needed to know since becoming
responsible for it. It's run from a complicated script that sets up it's
running environment, and I haven't yet figured out how to set up the
environment so I can run it on it's own. I may just create a modified
version of the script to run it inside the debugger.
>> I've checked the obvious: The argument of the delete is the name of a
>> pointer object that was initialized by a corresponding new-expression.
>> Execution of the code can't reach the delete-expression without first
>> passing through the new expression, and it only gets deleted once. That
>> pointer's non-null value was not changed between the new and delete
>> expressions. The pointer's value is passed to one subroutine, which
>> doesn't delete it, either. The object being allocated is an integer
>> array, so the implicit destructor should be a nop, with no failure modes
>> of it's own. What else can I check?
>
> Could it be the old favourite something else corrupting the heap?
That's what I'm assuming, by analogy with C, even though I know that
new/delete don't have any necessary connection with malloc() and free().
That's what I was implying in more generic form when talking about
writing past the end or before the beginning of a block of allocated
memory. I'm not looking forward to another heap corruption hunt through
unfamiliar code.
> Have/can you try running the code under something like valgrind?
I may have to - but my prior experience with valgrind suggests that it
produces too much information to make it easy to find the particular
issue that's actually causing a problem, particularly on poorly written
code like this.