Having a strange issue with std.net.curl.HTTP as a struct dependency

Adam D. Ruppe via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Wed Jul 12 06:47:06 PDT 2017


On Monday, 10 July 2017 at 00:10:36 UTC, NoBigDeal256 wrote:
> The error goes away. The error also goes away if 
> ThingA.arrayOfThingBs returns a single instance of ThingB 
> instead of an array of ThingB.

This tells me the problem is in the collection order at the end 
of the program.

The HTTP inside the struct inside the array gets cleaned up by 
the garbage collector (aka GC) at program termination... and it 
might be doing that AFTER unloading curl, leading to the 
segfault, OR it could be running some GC operation in the 
destructor, leading to InvalidMemoryOperationError (calling a GC 
function while the GC is running is not allowed). Which you get 
is apparently dependent on which system you are on, but both are 
wrong.

If it isn't in the array, the destructor gets called at scope 
exit, which happens before program termination and outside the 
GC, so everything happens as it is supposed to.


HTTP's innards have a RefCounted implementation which has a 
destructor that calls GC.removeRange. I *think* that can do the 
invalid mem operation. And the implementation itself can do 
curl_shutdown, which is your potential segfault.


So I'd say the answer is prolly to keep HTTP away from the GC. 
Manually free its arrays, or keep them outside arrays in the 
first place.


More information about the Digitalmars-d-learn mailing list