The deinit() method should not attempt to free memory that it does not own (avoiding the Invalid free error).
This could be achieved by tracking if loadDefaultProxies has been called and freeing the memory of proxy.host only in this case.
My alternative proposal would be to change the loadDefaultProxies method such that it returns the proxy - making the user in charge of freeing the memory I.e:
Zig Version
0.12.0-dev.2313+bf7ebfa67
Steps to Reproduce and Observed Behavior
The
deinit()
method ofstd.http.Client
currently assumes that it owns the memory of the underlyingproxy.host
variable https://github.com/ziglang/zig/blob/9e684e8d1af39904055abe64a9afda69a3d44a59/lib/std/http/Client.zig#L1056-L1079 This is only true, when the proxy has been set using theloadDefaultProxies
method https://github.com/ziglang/zig/blob/9e684e8d1af39904055abe64a9afda69a3d44a59/lib/std/http/Client.zig#L1083 If the proxy is set manually by the user, i.e.::The code will panic with the following error:
A workaround would be to force the user to allocate the
host
variable of the proxy on the heap and explicitly not freeing it, i.e.:Expected Behavior
The
deinit()
method should not attempt to free memory that it does not own (avoiding theInvalid free
error). This could be achieved by tracking ifloadDefaultProxies
has been called and freeing the memory ofproxy.host
only in this case. My alternative proposal would be to change theloadDefaultProxies
method such that it returns the proxy - making the user in charge of freeing the memory I.e: