$ git clone http://tcclient.ion.nu/tc_client.git
commit d7dee5d9c3aff905cddbe57b300c9671e9c9138c
Author: Alicia <...>
Date:   Wed Mar 22 10:29:34 2017 +0100

    tc_client-gtk: fixed segfault at exit by doing camera cleanup earlier.

diff --git a/ChangeLog b/ChangeLog
index b6a23f6..f52cde2 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -16,6 +16,7 @@ modbot: added an option (--no-unapproved) to not add any unapproved videos to qu
 tc_client-gtk: fixed a race-condition in the builtin video player.
 tc_client-gtk: fixed some memory leaks.
 tc_client-gtk: use /quit to guarantee a clean exit.
+tc_client-gtk: fixed segfault at exit by doing camera cleanup earlier.
 irchack: don't rely on connection ID.
 0.41.1:
 Use tinychat.com instead of apl.tinychat.com (works around SSL/TLS issues on windows)
diff --git a/utilities/gtk/camviewer.c b/utilities/gtk/camviewer.c
index 1f1e204..aa9250b 100644
--- a/utilities/gtk/camviewer.c
+++ b/utilities/gtk/camviewer.c
@@ -1015,6 +1015,7 @@ int main(int argc, char** argv)
   g_timeout_add(40, audiomixer, &audiopipe[1]);
 #endif
   gtk_main();
+  camera_cleanup();
   write(tc_client_in[1], "/quit\n", 6);
   write(greenroompipe_in[1], "/quit\n", 6);
   sleep(1);
@@ -1029,6 +1030,5 @@ int main(int argc, char** argv)
     TerminateProcess(grprocess.hProcess, 0);
   }
 #endif
-  camera_cleanup();
   return 0;
 }
diff --git a/utilities/gtk/media.c b/utilities/gtk/media.c
index a42e8dd..eb9a7fe 100644
--- a/utilities/gtk/media.c
+++ b/utilities/gtk/media.c
@@ -261,6 +261,7 @@ void camera_cleanup(void)
     camera_free(cams[i]);
   }
   free(cams);
+  camcount=0;
 }
 
 void freebuffer(guchar* pixels, gpointer data){free(pixels);}