ustd: destroy buffer struct after usage
authorPierre-Marc Fournier <pierre-marc.fournier@polymtl.ca>
Thu, 4 Mar 2010 22:46:46 +0000 (17:46 -0500)
committerPierre-Marc Fournier <pierre-marc.fournier@polymtl.ca>
Thu, 4 Mar 2010 22:55:24 +0000 (17:55 -0500)
libustcomm/ustcomm.c
ustd/ustd.c

index 60428df0553082bfaa35130b134008743421a202..259931d0be8e38a7811841e41218b7bb7cf9fa22 100644 (file)
@@ -425,7 +425,9 @@ int ustcomm_recv_message(struct ustcomm_server *server, char **msg, struct ustco
 
                                        list_for_each_entry(conn, &server->connections, list) {
                                                if(conn->fd == fds[idx].fd) {
+                                                       ustcomm_close_app(conn);
                                                        list_del(&conn->list);
+                                                       free(conn);
                                                        break;
                                                }
                                        }
@@ -636,7 +638,10 @@ int ustcomm_connect_app(pid_t pid, struct ustcomm_connection *conn)
        return ustcomm_connect_path(path, conn, pid);
 }
 
-/* Close a connection to a traceable app. */
+/* Close a connection to a traceable app. It frees the
+ * resources. It however does not free the
+ * ustcomm_connection itself.
+ */
 
 int ustcomm_close_app(struct ustcomm_connection *conn)
 {
@@ -784,11 +789,15 @@ static void ustcomm_fini_server(struct ustcomm_server *server, int keep_socket_f
        }
 }
 
+/* Free a traceable application server */
+
 void ustcomm_fini_app(struct ustcomm_app *handle, int keep_socket_file)
 {
        ustcomm_fini_server(&handle->server, keep_socket_file);
 }
 
+/* Free a ustd server */
+
 void ustcomm_fini_ustd(struct ustcomm_ustd *handle)
 {
        ustcomm_fini_server(&handle->server, 0);
index 4db550222407ba7d0773aa8b15e1b33cda777de2..8eeb62ba361aa0a7696b7540a827fb24b6cafb4e 100644 (file)
@@ -86,11 +86,10 @@ int get_subbuffer(struct buffer_info *buf)
        if(result != 2 && result != 1) {
                ERR("unable to parse response to get_subbuffer");
                retval = -1;
+               free(received_msg);
                goto end_rep;
        }
 
-       DBG("received msg is %s", received_msg);
-
        if(!strcmp(rep_code, "OK")) {
                DBG("got subbuffer %s", buf->name);
                retval = GET_SUBBUF_OK;
@@ -400,6 +399,33 @@ error:
        return NULL;
 }
 
+static void destroy_buffer(struct buffer_info *buf)
+{
+       int result;
+
+       result = ustcomm_close_app(&buf->conn);
+       if(result == -1) {
+               WARN("problem calling ustcomm_close_app");
+       }
+
+       result = shmdt(buf->mem);
+       if(result == -1) {
+               PERROR("shmdt");
+       }
+
+       result = shmdt(buf->bufstruct_mem);
+       if(result == -1) {
+               PERROR("shmdt");
+       }
+
+       result = close(buf->file_fd);
+       if(result == -1) {
+               PERROR("close");
+       }
+
+       free(buf);
+}
+
 int unwrite_last_subbuffer(struct buffer_info *buf)
 {
        int result;
@@ -513,10 +539,6 @@ int consumer_loop(struct buffer_info *buf)
        return 0;
 }
 
-void free_buffer(struct buffer_info *buf)
-{
-}
-
 struct consumer_thread_args {
        pid_t pid;
        const char *bufname;
@@ -537,7 +559,8 @@ void *consumer_thread(void *arg)
 
        consumer_loop(buf);
 
-       free_buffer(buf);
+       free(args->bufname);
+       destroy_buffer(buf);
 
        end:
        /* bufname is free'd in free_buffer() */
@@ -549,6 +572,7 @@ int start_consuming_buffer(pid_t pid, const char *bufname)
 {
        pthread_t thr;
        struct consumer_thread_args *args;
+       int result;
 
        DBG("beginning of start_consuming_buffer: args: pid %d bufname %s", pid, bufname);
 
@@ -558,7 +582,16 @@ int start_consuming_buffer(pid_t pid, const char *bufname)
        args->bufname = strdup(bufname);
        DBG("beginning2 of start_consuming_buffer: args: pid %d bufname %s", args->pid, args->bufname);
 
-       pthread_create(&thr, NULL, consumer_thread, args);
+       result = pthread_create(&thr, NULL, consumer_thread, args);
+       if(result == -1) {
+               ERR("pthread_create failed");
+               return -1;
+       }
+       result = pthread_detach(thr);
+       if(result == -1) {
+               ERR("pthread_detach failed");
+               return -1;
+       }
        DBG("end of start_consuming_buffer: args: pid %d bufname %s", args->pid, args->bufname);
 
        return 0;
This page took 0.027647 seconds and 4 git commands to generate.