Fix memory leak in rigctld and cleanup debug

pull/155/head
Michael Black 2019-12-20 11:22:09 -06:00
rodzic 1dbd633d5a
commit a401d3ac78
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 6599353EC683404D
2 zmienionych plików z 33 dodań i 28 usunięć

Wyświetl plik

@ -473,6 +473,7 @@ static int scanfc(FILE *fin, const char *format, void *p)
{
do
{
*(char *)p = 0;
int ret = fscanf(fin, format, p);
if (ret < 0)
@ -482,11 +483,13 @@ static int scanfc(FILE *fin, const char *format, void *p)
continue;
}
rig_debug(RIG_DEBUG_ERR, "fscanf: %s\n", strerror(errno));
rig_debug(RIG_DEBUG_ERR,
"fscanf: parsing '%s' with '%s'\n",
(char *)p,
format);
if (!feof(fin))
{
rig_debug(RIG_DEBUG_ERR,
"fscanf: parsing '%s' with '%s'\n",
(char *)p,
format);
}
}
return ret;
@ -618,6 +621,7 @@ int rigctl_parse(RIG *my_rig, FILE *fin, FILE *fout, char *argv[], int argc,
if (interactive)
{
static int last_was_ret = 1;
if (prompt)
{
fprintf_flush(fout, "\nRig command: ");
@ -4142,7 +4146,7 @@ declare_proto_rig(send_cmd)
{
char tmpbuf[64];
/* text protocol */
strncpy(bufcmd, arg1, BUFSZ-1);
strncpy(bufcmd, arg1, BUFSZ - 1);
strtok(bufcmd, "\0xa\0xd");
bufcmd[BUFSZ - 2] = '\0';
cmd_len = strlen(bufcmd);
@ -4245,7 +4249,7 @@ declare_proto_rig(send_cmd)
hexbuf = realloc(hexbuf, hexbufbytes);
}
strncat(hexbuf, hex, hexbufbytes-1);
strncat(hexbuf, hex, hexbufbytes - 1);
}
rig_debug(RIG_DEBUG_TRACE, "%s: binary=%s, retval=%d\n", __func__, hexbuf,

Wyświetl plik

@ -585,7 +585,7 @@ int main(int argc, char *argv[])
exit(2);
}
if (verbose > 0)
if (verbose > RIG_DEBUG_ERR)
{
printf("Opened rig model %d, '%s'\n",
my_rig->caps->rig_model,
@ -597,7 +597,7 @@ int main(int argc, char *argv[])
rig_close(my_rig); /* we will reopen for clients */
if (verbose > 0)
if (verbose > RIG_DEBUG_ERR)
{
printf("Closed rig model %d, '%s - will reopen for clients'\n",
my_rig->caps->rig_model,
@ -721,7 +721,7 @@ int main(int argc, char *argv[])
if (listen(sock_listen, 4) < 0)
{
handle_error(RIG_DEBUG_ERR, "listeningn");
handle_error(RIG_DEBUG_ERR, "listening");
exit(1);
}
@ -895,8 +895,8 @@ int main(int argc, char *argv[])
void *handle_socket(void *arg)
{
struct handle_data *handle_data_arg = (struct handle_data *)arg;
FILE *fsockin;
FILE *fsockout;
FILE *fsockin = NULL;
FILE *fsockout = NULL;
int retcode = RIG_OK;
char host[NI_MAXHOST];
char serv[NI_MAXSERV];
@ -945,7 +945,7 @@ void *handle_socket(void *arg)
{
retcode = rig_open(my_rig);
if (RIG_OK == retcode && verbose > 0)
if (RIG_OK == retcode && verbose > RIG_DEBUG_ERR)
{
printf("Opened rig model %d, '%s'\n",
my_rig->caps->rig_model,
@ -957,7 +957,7 @@ void *handle_socket(void *arg)
#else
retcode = rig_open(my_rig);
if (RIG_OK == retcode && verbose > 0)
if (RIG_OK == retcode && verbose > RIG_DEBUG_ERR)
{
printf("Opened rig model %d, '%s'\n",
my_rig->caps->rig_model,
@ -979,7 +979,6 @@ void *handle_socket(void *arg)
if (retcode == 1)
{
rig_close(my_rig);
retcode = rig_open(my_rig);
}
}
@ -993,7 +992,7 @@ void *handle_socket(void *arg)
{
rig_close(my_rig);
if (verbose > 0)
if (verbose > RIG_DEBUG_ERR)
{
printf("Closed rig model %d, '%s - no clients, will reopen for new clients'\n",
my_rig->caps->rig_model,
@ -1005,7 +1004,7 @@ void *handle_socket(void *arg)
#else
rig_close(my_rig);
if (verbose > 0)
if (verbose > RIG_DEBUG_ERR)
{
printf("Closed rig model %d, '%s - will reopen for new clients'\n",
my_rig->caps->rig_model,
@ -1032,24 +1031,26 @@ void *handle_socket(void *arg)
host,
serv);
retcode = fclose(fsockin);
handle_exit:
// for MINGW we close the handle before fclose
#ifdef __MINGW32__
retcode = closesocket(handle_data_arg->sock);
if (retcode != 0) { rig_debug(RIG_DEBUG_ERR, "%s: fclose(fsockin) %s\n", __func__, strerror(retcode)); }
#endif
fclose(fsockin);
fclose(fsockout);
// for everybody else we close the handle after fclose
#ifndef __MINGW32__
rig_debug(RIG_DEBUG_ERR,"%s: fclose(fsockout)\n", __func__);
retcode = fclose(fsockout);
retcode = close(handle_data_arg->sock);
if (retcode != 0) { rig_debug(RIG_DEBUG_ERR, "%s: close(handle_data_arg->sock) %s\n", __func__, strerror(retcode)); }
if (retcode != 0) { rig_debug(RIG_DEBUG_ERR, "%s: fclose(fsockout) %s\n", __func__, strerror(retcode)); }
#endif
handle_exit:
#ifdef __MINGW32__
shutdown(handle_data_arg->sock, 2);
closesocket(handle_data_arg->sock);
#else
close(handle_data_arg->sock);
#endif
free(arg);
#ifdef HAVE_PTHREAD