From 46f2f102fa22ddffe515546e7db21cf208db0d90 Mon Sep 17 00:00:00 2001 From: Andre Noll Date: Sun, 22 Mar 2009 13:58:28 +0100 Subject: [PATCH] Fix some memory leaks. In fact, there was only one "real" leak: An empty info string (100 bytes) could leak on file change. --- command.c | 8 +++++--- server.c | 3 +++ vss.c | 2 +- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/command.c b/command.c index b59fae7a..d08a7181 100644 --- 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: diff --git a/server.c b/server.c index 4415cdcd..1e4caf08 100644 --- 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 066a8851..10780cbf 100644 --- 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; -- 2.39.5