Fix some memory leaks.
authorAndre Noll <maan@systemlinux.org>
Sun, 22 Mar 2009 12:58:28 +0000 (13:58 +0100)
committerAndre Noll <maan@systemlinux.org>
Sun, 22 Mar 2009 12:58:28 +0000 (13:58 +0100)
In fact, there was only one "real" leak: An empty info string (100
bytes) could leak on file change.

command.c
server.c
vss.c

index b59fae7..d08a718 100644 (file)
--- a/command.c
+++ b/command.c
@@ -787,12 +787,14 @@ __noreturn void handle_connect(int fd, const char *peername)
        /* valid command and sufficient perms */
        alarm(0);
        argc = split_args(command, &argv, "\n");
-       mutex_lock(mmd_mutex);
-       mmd->num_commands++;
-       mutex_unlock(mmd_mutex);
        PARA_NOTICE_LOG("calling com_%s() for %s@%s\n", cmd->name, u->name,
                        peername);
        ret = cmd->handler(fd, argc, argv);
+       mutex_lock(mmd_mutex);
+       mmd->num_commands++;
+       free(mmd->afd.afhi.info_string);
+       free(mmd->afd.afhi.chunk_table);
+       mutex_unlock(mmd_mutex);
        if (ret >= 0)
                goto out;
 err_out:
index 4415cdc..1e4caf0 100644 (file)
--- a/server.c
+++ b/server.c
@@ -300,6 +300,9 @@ static void signal_post_select(struct sched *s, struct task *t)
                PARA_EMERG_LOG("terminating on signal %d\n", st->signum);
 genocide:
                kill(0, SIGTERM);
+               free(mmd->afd.afhi.chunk_table);
+               free(mmd->afd.afhi.info_string);
+               close_listed_fds();
                mutex_destroy(mmd_mutex);
                shm_detach(mmd);
                exit(EXIT_FAILURE);
diff --git a/vss.c b/vss.c
index 066a885..10780cb 100644 (file)
--- a/vss.c
+++ b/vss.c
@@ -740,7 +740,6 @@ static void recv_afs_result(struct vss_task *vsst)
        struct stat statbuf;
 
        vsst->afsss = AFS_SOCKET_READY;
-       mmd->afd.afhi.chunk_table = NULL;
        ret = recv_afs_msg(vsst->afs_socket, &passed_fd, &afs_code, &afs_data);
        if (ret < 0)
                goto err;
@@ -752,6 +751,7 @@ static void recv_afs_result(struct vss_task *vsst)
        if (passed_fd < 0)
                goto err;
        shmid = afs_data;
+       free(mmd->afd.afhi.info_string);
        ret = load_afd(shmid, &mmd->afd);
        if (ret < 0)
                goto err;