[vlc-devel] [PATCH] win32: only call WSACleanup if WSAStartup worked

Steve Lhomme robux4 at ycbcr.xyz
Fri Mar 27 09:31:49 CET 2020


On 2020-03-27 9:20, Rémi Denis-Courmont wrote:
> Le perjantaina 27. maaliskuuta 2020, 9.55.34 EET Steve Lhomme a écrit :
>> According to the documentation:
>> There must be a call to WSACleanup for each successful call to WSAStartup.
>> Only the final WSACleanup function call performs the actual cleanup.
>> ---
>>   src/win32/specific.c | 10 ++++++++--
>>   1 file changed, 8 insertions(+), 2 deletions(-)
>>
>> diff --git a/src/win32/specific.c b/src/win32/specific.c
>> index cf5836af0b6..75e0f7f5c51 100644
>> --- a/src/win32/specific.c
>> +++ b/src/win32/specific.c
>> @@ -36,6 +36,8 @@
>>   #include <mmsystem.h>
>>   #include <winsock2.h>
>>
>> +static bool WSA_initialized = false;
>> +
>>   static int system_InitWSA(int hi, int lo)
>>   {
>>       WSADATA data;
>> @@ -43,10 +45,14 @@ static int system_InitWSA(int hi, int lo)
>>       if (WSAStartup(MAKEWORD(hi, lo), &data) == 0)
>>       {
>>           if (LOBYTE(data.wVersion) == 2 && HIBYTE(data.wVersion) == 2)
>> +        {
>> +            WSA_initialized = true;
>>               return 0;
>> +        }
>>           /* Winsock DLL is not usable */
>>           WSACleanup( );
>>       }
>> +    WSA_initialized = false;
>>       return -1;
>>   }
>>
>> @@ -173,6 +179,6 @@ void system_Configure( libvlc_int_t *p_this, int i_argc,
>> const char *const ppsz_ */
>>   void system_End(void)
>>   {
>> -    /* XXX: In theory, we should not call this if WSAStartup() failed. */
>> -    WSACleanup();
>> +    if (WSA_initialized)
>> +        WSACleanup();
>>   }
> 
> Won't work with multiple instances.

Then I guess we need to do the refcounting ourself...


More information about the vlc-devel mailing list