Understanding SIGSEGV issues
schveiguy at gmail.com
Thu Jan 10 15:00:00 UTC 2019
On 1/9/19 11:39 AM, Russel Winder wrote:
> On Tue, 2019-01-08 at 09:59 -0500, Steven Schveighoffer via Digitalmars-d-
> learn wrote:
>> Russel, make sure your destructor both checks whether the underlying
>> resource is set, and clears it to invalid when freeing it.
>> Even types that can't be copied can be moved, or temporarily created as
>> rvalues. When they are moved the shell they get moved out of is still
>> destructed! So it has to have a state where it can be destroyed, even
>> though there is no resource.
> I have added tests in the destructor but given the constructor should throw an
> exception on a failure to initialise the internal state correctly, it really
> ought to be unnecessary. but I guess it cant hurt being there!
The point is that some libraries are not robust enough to handle freeing
data multiple times. And with the way postblit/dtors work, you have to
handle this properly in D.
> As I noted to Nicholas it seems the application is getting a valid data
> structure returned with invalid data and that is where the SIGSEGV is. This is
> really weird as I have just finished a Rust version of the same application
> and it works fine. And this D version used to work fine. It is a real mystery
> why there is a problem now.
Hm... your description of having the problem happen at the end of main
seems to suggest it has something to do with destruction.
More information about the Digitalmars-d-learn