old-dab/rtlsdr

Crash in rtl_tcp

Closed this issue · 1 comments

On Windows, simply running rtl_tcp.exe for a few seconds. Then pressing ^C, it crashes inside Pthreads-W32.
Call-stack shows it happens via librtlsdr.c and rtlsdr_set_i2c_repeater().

AFAICS, since the ctrl_thread_fn() function calls rtlsdr_get_tuner_i2c_register() after rtlsdr_close() was called in the
main thread.

A fix for me was to move rtlsdr_close() further down:

--- a/src/rtl_tcp.c 2022-01-10 11:19:23
+++ b/src/rtl_tcp.c 2022-01-12 09:48:38
@@ -910,14 +910,14 @@
        }

 out:
-       if(dev)
-               rtlsdr_close(dev);
        closesocket(listensocket);
        if ( port_resp ) {
                do_exit_thrd_ctrl = 1;
                ctrldata.pDoExit = &do_exit_thrd_ctrl;
                pthread_join(thread_ctrl, &status);
        }
+       if(dev)
+               rtlsdr_close(dev);
        closesocket(s);
 #ifdef _WIN32
        WSACleanup();

Done! Thank you very much!