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
Hamlib-1.2.8
Stéphane Fillod, F8CFE 2008-09-17 18:56:13 +00:00
rodzic 0049d2acd7
commit 591f77e271
2 zmienionych plików z 20 dodań i 4 usunięć

Wyświetl plik

@ -4,7 +4,7 @@
* This program test/control a radio using Hamlib. * This program test/control a radio using Hamlib.
* It takes commands from network connection. * 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 * This program is free software; you can redistribute it and/or
@ -390,7 +390,7 @@ int main (int argc, char *argv[])
#ifdef HAVE_PTHREAD #ifdef HAVE_PTHREAD
retcode = pthread_create(&thread, NULL, handle_socket, arg); 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)); rig_debug(RIG_DEBUG_ERR, "pthread_create: %s\n", strerror(retcode));
break; break;
} }
@ -420,19 +420,24 @@ void * handle_socket(void *arg)
fsockin = fdopen(handle_data_arg->sock, "rb"); fsockin = fdopen(handle_data_arg->sock, "rb");
if (!fsockin) { if (!fsockin) {
rig_debug(RIG_DEBUG_ERR, "fdopen in: %s\n", strerror(errno)); rig_debug(RIG_DEBUG_ERR, "fdopen in: %s\n", strerror(errno));
close(handle_data_arg->sock);
free(arg); free(arg);
#ifdef HAVE_PTHREAD #ifdef HAVE_PTHREAD
pthread_exit(NULL); pthread_exit(NULL);
#endif #endif
return NULL;
} }
fsockout = fdopen(handle_data_arg->sock, "wb"); fsockout = fdopen(handle_data_arg->sock, "wb");
if (!fsockout) { if (!fsockout) {
rig_debug(RIG_DEBUG_ERR, "fdopen out: %s\n", strerror(errno)); rig_debug(RIG_DEBUG_ERR, "fdopen out: %s\n", strerror(errno));
fclose(fsockin);
close(handle_data_arg->sock);
free(arg); free(arg);
#ifdef HAVE_PTHREAD #ifdef HAVE_PTHREAD
pthread_exit(NULL); pthread_exit(NULL);
#endif #endif
return NULL;
} }
do { do {
@ -451,6 +456,9 @@ void * handle_socket(void *arg)
close(handle_data_arg->sock); close(handle_data_arg->sock);
free(arg); free(arg);
#ifdef HAVE_PTHREAD
pthread_exit(NULL);
#endif
return NULL; return NULL;
} }

Wyświetl plik

@ -4,7 +4,7 @@
* This program test/control a rotator using Hamlib. * This program test/control a rotator using Hamlib.
* It takes commands from network connection. * 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 * This program is free software; you can redistribute it and/or
@ -290,7 +290,7 @@ int main (int argc, char *argv[])
#ifdef HAVE_PTHREAD #ifdef HAVE_PTHREAD
retcode = pthread_create(&thread, NULL, handle_socket, arg); 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)); rig_debug(RIG_DEBUG_ERR, "pthread_create: %s\n", strerror(retcode));
break; break;
} }
@ -321,18 +321,23 @@ void * handle_socket(void *arg)
if (!fsockin) { if (!fsockin) {
rig_debug(RIG_DEBUG_ERR, "fdopen in: %s\n", strerror(errno)); rig_debug(RIG_DEBUG_ERR, "fdopen in: %s\n", strerror(errno));
free(arg); free(arg);
close(handle_data_arg->sock);
#ifdef HAVE_PTHREAD #ifdef HAVE_PTHREAD
pthread_exit(NULL); pthread_exit(NULL);
#endif #endif
return NULL;
} }
fsockout = fdopen(handle_data_arg->sock, "wb"); fsockout = fdopen(handle_data_arg->sock, "wb");
if (!fsockout) { if (!fsockout) {
rig_debug(RIG_DEBUG_ERR, "fdopen out: %s\n", strerror(errno)); rig_debug(RIG_DEBUG_ERR, "fdopen out: %s\n", strerror(errno));
fclose(fsockin);
close(handle_data_arg->sock);
free(arg); free(arg);
#ifdef HAVE_PTHREAD #ifdef HAVE_PTHREAD
pthread_exit(NULL); pthread_exit(NULL);
#endif #endif
return NULL;
} }
do { do {
@ -351,6 +356,9 @@ void * handle_socket(void *arg)
close(handle_data_arg->sock); close(handle_data_arg->sock);
free(arg); free(arg);
#ifdef HAVE_PTHREAD
pthread_exit(NULL);
#endif
return NULL; return NULL;
} }