Silicondust / libhdhomerun

Silicondust library and cli utility for controlling HDHomeRun tuners
GNU Lesser General Public License v2.1
110 stars 44 forks source link

Use RtlGenRandom when available to eliminate TLS and heap leaks #22

Closed djp952 closed 2 years ago

djp952 commented 5 years ago

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.

djp952 commented 2 years ago

Request superseded by changes in release 20220302; thank you.