The implementation of random_get32 in hdhomerun_os_windows.c leaks all sorts of things:
The TLS slot
The heap memory allocated for the HCRYPTPROV handle
The HCRYPTPROV handle itself
There is a function available in Desktop Windows since XP, RtlGenRandom(), that can perform the same operation without needing all of these things. The function is a little odd since it's actually called SystemFunction036 but Microsoft has dealt with this in the SDK headers so no tricks are necessary.
The proposed change simplifies the code, avoids the various leaks, and if the platform / SDK version doesn't support the RtlGenRandom macro the function will fall back to getcurrenttime() as it would for WINRT or if an error occurred.
The implementation of random_get32 in hdhomerun_os_windows.c leaks all sorts of things:
There is a function available in Desktop Windows since XP, RtlGenRandom(), that can perform the same operation without needing all of these things. The function is a little odd since it's actually called SystemFunction036 but Microsoft has dealt with this in the SDK headers so no tricks are necessary.
The proposed change simplifies the code, avoids the various leaks, and if the platform / SDK version doesn't support the RtlGenRandom macro the function will fall back to getcurrenttime() as it would for WINRT or if an error occurred.