Remove client_disconnect().
authorAndre Noll <maan@systemlinux.org>
Tue, 31 Dec 2013 15:44:24 +0000 (15:44 +0000)
committerAndre Noll <maan@systemlinux.org>
Sat, 3 May 2014 12:08:00 +0000 (14:08 +0200)
Everything this function does can be done as well when the task
terminates by returning negative in ->post_select().

This also avoids to leak the stream cipher structure of the previous
connection when running in interactive mode.

1,032 bytes in 1 blocks are definitely lost in loss record 61 of 85
   at 0x402994A: malloc (vg_replace_malloc.c:263)
   by 0x804C689: para_malloc (string.c:71)
   by 0x804FF87: sc_new (crypt.c:268)
   by 0x804E204: client_post_select (client_common.c:370)
   by 0x804D203: schedule (sched.c:59)
   by 0x804A2E7: main (client.c:500)

1,032 bytes in 1 blocks are definitely lost in loss record 62 of 85
   at 0x402994A: malloc (vg_replace_malloc.c:263)
   by 0x804C689: para_malloc (string.c:71)
   by 0x804FF87: sc_new (crypt.c:268)
   by 0x804E217: client_post_select (client_common.c:371)
   by 0x804D203: schedule (sched.c:59)
   by 0x804A2E7: main (client.c:500)

client.c
client.h
client_common.c

index c1ef5217345eb96720e7ce81e495e681f6d774f2..b39a8b0199f0fbe66f95c12a34c5c6b05b5d23d7 100644 (file)
--- a/client.c
+++ b/client.c
@@ -114,7 +114,6 @@ static int execute_client_command(const char *cmd, char **result)
        schedule(&command_sched);
        *result = exec_task.result_buf;
        btr_remove_node(&exec_task.btrn);
        schedule(&command_sched);
        *result = exec_task.result_buf;
        btr_remove_node(&exec_task.btrn);
-       client_disconnect(ct);
        ret = 1;
 out:
        btr_remove_node(&exec_task.btrn);
        ret = 1;
 out:
        btr_remove_node(&exec_task.btrn);
@@ -444,7 +443,6 @@ static int client_i9e_line_handler(char *line)
 {
        int ret;
 
 {
        int ret;
 
-       client_disconnect(ct);
        PARA_DEBUG_LOG("line: %s\n", line);
        ret = make_client_argv(line);
        if (ret <= 0)
        PARA_DEBUG_LOG("line: %s\n", line);
        ret = make_client_argv(line);
        if (ret <= 0)
index 82dbc03327260cb9d3810c47f0e8d972f421d70e..e304f0923693b5913a5224c4be8327a0fa6795f1 100644 (file)
--- a/client.h
+++ b/client.h
@@ -52,7 +52,6 @@ struct client_task {
        char **features;
 };
 
        char **features;
 };
 
-void client_disconnect(struct client_task *ct);
 void client_close(struct client_task *ct);
 int client_parse_config(int argc, char *argv[], struct client_task **ct_ptr,
                int *loglevel);
 void client_close(struct client_task *ct);
 int client_parse_config(int argc, char *argv[], struct client_task **ct_ptr,
                int *loglevel);
index 900d3653893dea7067330d60a929ce0a4b13d902..8212abb1d611dcff88889fa70629fcdc9f6eb5cf 100644 (file)
 /** The size of the receiving buffer. */
 #define CLIENT_BUFSIZE 4000
 
 /** The size of the receiving buffer. */
 #define CLIENT_BUFSIZE 4000
 
-/**
- * Close the connection to para_server and deallocate per-command resources.
- *
- * \param ct The client task.
- *
- * This frees all resources of the current command but keeps the configuration
- * in \p ct->conf.
- *
- * \sa \ref client_close().
- */
-void client_disconnect(struct client_task *ct)
-{
-       if (!ct)
-               return;
-       if (ct->scc.fd >= 0)
-               close(ct->scc.fd);
-       free_argv(ct->features);
-       ct->features = NULL;
-       sc_free(ct->scc.recv);
-       ct->scc.recv = NULL;
-       sc_free(ct->scc.send);
-       ct->scc.send = NULL;
-       btr_remove_node(&ct->btrn[0]);
-       btr_remove_node(&ct->btrn[1]);
-}
-
 /**
  * Close the connection to para_server and free all resources.
  *
  * \param ct Pointer to the client data.
  *
 /**
  * Close the connection to para_server and free all resources.
  *
  * \param ct Pointer to the client data.
  *
- * \sa \ref client_open(), \ref client_disconnect().
+ * \sa \ref client_open().
  */
 void client_close(struct client_task *ct)
 {
        if (!ct)
                return;
  */
 void client_close(struct client_task *ct)
 {
        if (!ct)
                return;
-       client_disconnect(ct);
        free(ct->user);
        free(ct->config_file);
        free(ct->key_file);
        free(ct->user);
        free(ct->config_file);
        free(ct->key_file);
@@ -476,6 +449,16 @@ out:
        btr_remove_node(&ct->btrn[1]);
        if (ret != -E_SERVER_CMD_SUCCESS && ret != -E_SERVER_CMD_FAILURE)
                PARA_ERROR_LOG("%s\n", para_strerror(-ret));
        btr_remove_node(&ct->btrn[1]);
        if (ret != -E_SERVER_CMD_SUCCESS && ret != -E_SERVER_CMD_FAILURE)
                PARA_ERROR_LOG("%s\n", para_strerror(-ret));
+       if (ct->scc.fd >= 0) {
+               close(ct->scc.fd);
+               ct->scc.fd = -1;
+       }
+       free_argv(ct->features);
+       ct->features = NULL;
+       sc_free(ct->scc.recv);
+       ct->scc.recv = NULL;
+       sc_free(ct->scc.send);
+       ct->scc.send = NULL;
        return ret;
 }
 
        return ret;
 }