Repository navigation
Conversation
wcsdup callback initialization in curl_global_init()wcsdup callback init in curl_global_init()
wcsdup callback init in curl_global_init()wcsdup callback in curl_global_init()
|
@jay What do you think? |
|
re #7540 (comment) it looks like he's correct and I think we should give him credit Curl_cwcsdup isn't set in curl_global_init_mem presumably because there's no wcsdup callback that the user can set. We probably thought it would be covered since the user sets a malloc callback which is then called by our internal wcsdup (Curl_wcsdup) but wcsdup (defined to Curl_cwcsdup pointer) doesn't always point to Curl_wcsdup. So your fix is right, #if defined(_WIN32) && defined(UNICODE)
- Curl_cwcsdup = (curl_wcsdup_callback)_wcsdup;
+ Curl_cwcsdup = (curl_wcsdup_callback)Curl_wcsdup;
#endifhowever it makes that line redundant. It's already set before main so you could just remove those 3 lines instead. Another way that may be more palatable is leave the line in curl_global_init unchanged and add the line to curl_global_init_mem instead. There may be some slight performance benefit to have curl_global_init (ie no user memory callbacks) continue to call _wcsdup directly. Possibly though I'm forgetting something like trackmemory needs to track it. So 3 different ways to do it, one of the ways is the most correct but I'm not sure which. |
Also: - add two related casts to match rest of code. - replace deprecated `wcsdup` with `_wcsdup` in libtests. Ref: https://learn.microsoft.com/cpp/c-runtime-library/reference/strdup-wcsdup Follow-up to 76e047f curl#7540 Bug: curl#17840 (comment) Bug: curl#7540 (comment) Closes curl#17840
|
In theory someone might rely on this reset behavior if setting I think setting it to I'm now wondering if it'd be possible to just Credits: The original report remained hidden until I bumped into this issue while |
wcsdup callback in curl_global_init()curl_wcsdup_callback callback
curl_wcsdup_callback callbackcurl_wcsdup_callback callback
|
Dropping the Windows-specific, redundant, callback, seems to work fine. |
Ah the fourth way. Yes, that works :)
Sure, however you think is best. |
This callback was permanently mapped to libcurl's internal
Curl_wcsdup(), which always uses the customizable malloc forallocation, thus making a custom mapping redundant anyway.
To simplify, drop the callback and map
_tcsdup()in Unicode modedirectly to
Curl_wcsdup().Also fixes:
curl_global_init()which, before this patch, (re)initialized itsmapping to
_wcsdup(), returning buffers potentially incompatiblewith a custom allocator.
Bug: memory: stop overriding unused
wcsdup()/_wcsdup()system functions #17840 (comment)Bug: Use a custom implementation of wcsdup on Windows, so that malloc/free… #7540 (comment)
Co-reported-by: Luca Kellermann
Follow-up to 76e047f #7540
Assisted-by: Jay Satiro
Closes #17843