std.process: memory allocation with malloc in execv_
Steven Schveighoffer
schveiguy at gmail.com
Tue Jan 31 15:29:35 UTC 2023
On 1/30/23 12:56 PM, kdevel wrote:
> On Monday, 30 January 2023 at 17:19:13 UTC, Steven Schveighoffer wrote:
>>> [...]
>>> 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.
>
> There is no indication that the GC kicks in after patching (v0)
>
> https://issues.dlang.org/attachment.cgi?id=1868&action=diff
>
> I have a patch v1 in preparation which removes the wrappers entirely.
> BTW: There is a non-POSIX function execvpe in the process.d which is
> actually a GNU extension.
Using `GC.disable` ensures the GC will not run when you allocate memory.
Whether it runs or not is up to the memory allocator. There is no
guarantee it will run, so checking whether it did run is not conclusive.
Running a collection just before replacing the entire image with another
program isn't productive work.
Just add:
```d
GC.disable;
scope(exit) GC.enable;
```
to the part where you are about to set up the call to `exec`
-Steve
More information about the Digitalmars-d
mailing list