std.process: memory allocation with malloc in execv_

Steven Schveighoffer schveiguy at gmail.com
Mon Jan 30 17:19:13 UTC 2023


On 1/27/23 3:26 PM, kdevel wrote:
> On Thursday, 26 January 2023 at 14:45:29 UTC, Steven Schveighoffer wrote:

>> I don't like the solution of adding the range, or using the GC. A 
>> better option is to replace toAStringz with a function that creates 
>> everything for you into a type (toStringz isn't complex, just replace 
>> with one that uses malloc), that then automatically frees everything.
> 
> Freeing the memory is — in the "happy path" — neither required nor 
> possible. When unhappy the GC is ready to clean up the mess. I uploaded 
> a patch to the issue.

It's actually fine to use GC, you are right. But use `GC.disable` before 
using it (with a `scope(exit)` to re-enable), because running a GC just 
before exec is also pointless.

> 
> How do I check my patched version without editing the module name in 
> process.d? Either I don't get the functions linked into the executable 
> or the linker complains about duplicate symbols.

I don't think you can. But building phobos is pretty quick.

-Steve


More information about the Digitalmars-d mailing list