From 591f77e271e0dae9131bfb6cc9df912c06ba2c8a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Fillod=2C=20F8CFE?= Date: Wed, 17 Sep 2008 18:56:13 +0000 Subject: [PATCH] fix thread-leak and pthread_create error code checking git-svn-id: https://hamlib.svn.sourceforge.net/svnroot/hamlib/trunk@2388 7ae35d74-ebe9-4afe-98af-79ac388436b8 --- tests/rigctld.c | 12 ++++++++++-- tests/rotctld.c | 12 ++++++++++-- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/tests/rigctld.c b/tests/rigctld.c index f547d0a9f..24627aa02 100644 --- a/tests/rigctld.c +++ b/tests/rigctld.c @@ -4,7 +4,7 @@ * This program test/control a radio using Hamlib. * It takes commands from network connection. * - * $Id: rigctld.c,v 1.5 2008-05-08 16:21:33 fillods Exp $ + * $Id: rigctld.c,v 1.6 2008-09-17 18:56:13 fillods Exp $ * * * This program is free software; you can redistribute it and/or @@ -390,7 +390,7 @@ int main (int argc, char *argv[]) #ifdef HAVE_PTHREAD retcode = pthread_create(&thread, NULL, handle_socket, arg); - if (retcode < 0) { + if (retcode != 0) { rig_debug(RIG_DEBUG_ERR, "pthread_create: %s\n", strerror(retcode)); break; } @@ -420,19 +420,24 @@ void * handle_socket(void *arg) fsockin = fdopen(handle_data_arg->sock, "rb"); if (!fsockin) { rig_debug(RIG_DEBUG_ERR, "fdopen in: %s\n", strerror(errno)); + close(handle_data_arg->sock); free(arg); #ifdef HAVE_PTHREAD pthread_exit(NULL); #endif + return NULL; } fsockout = fdopen(handle_data_arg->sock, "wb"); if (!fsockout) { rig_debug(RIG_DEBUG_ERR, "fdopen out: %s\n", strerror(errno)); + fclose(fsockin); + close(handle_data_arg->sock); free(arg); #ifdef HAVE_PTHREAD pthread_exit(NULL); #endif + return NULL; } do { @@ -451,6 +456,9 @@ void * handle_socket(void *arg) close(handle_data_arg->sock); free(arg); +#ifdef HAVE_PTHREAD + pthread_exit(NULL); +#endif return NULL; } diff --git a/tests/rotctld.c b/tests/rotctld.c index c99eb79a7..79720a3c8 100644 --- a/tests/rotctld.c +++ b/tests/rotctld.c @@ -4,7 +4,7 @@ * This program test/control a rotator using Hamlib. * It takes commands from network connection. * - * $Id: rotctld.c,v 1.1 2008-09-12 22:55:09 fillods Exp $ + * $Id: rotctld.c,v 1.2 2008-09-17 18:56:13 fillods Exp $ * * * This program is free software; you can redistribute it and/or @@ -290,7 +290,7 @@ int main (int argc, char *argv[]) #ifdef HAVE_PTHREAD retcode = pthread_create(&thread, NULL, handle_socket, arg); - if (retcode < 0) { + if (retcode != 0) { rig_debug(RIG_DEBUG_ERR, "pthread_create: %s\n", strerror(retcode)); break; } @@ -321,18 +321,23 @@ void * handle_socket(void *arg) if (!fsockin) { rig_debug(RIG_DEBUG_ERR, "fdopen in: %s\n", strerror(errno)); free(arg); + close(handle_data_arg->sock); #ifdef HAVE_PTHREAD pthread_exit(NULL); #endif + return NULL; } fsockout = fdopen(handle_data_arg->sock, "wb"); if (!fsockout) { rig_debug(RIG_DEBUG_ERR, "fdopen out: %s\n", strerror(errno)); + fclose(fsockin); + close(handle_data_arg->sock); free(arg); #ifdef HAVE_PTHREAD pthread_exit(NULL); #endif + return NULL; } do { @@ -351,6 +356,9 @@ void * handle_socket(void *arg) close(handle_data_arg->sock); free(arg); +#ifdef HAVE_PTHREAD + pthread_exit(NULL); +#endif return NULL; }