From ccfe1b9654dbe780bc297fa270e5b1ba78f63360 Mon Sep 17 00:00:00 2001 From: Stefan Berger Date: Thu, 9 Aug 2018 08:46:31 -0400 Subject: [PATCH] swtpm: fix memory leak when freeing server struct upon exit This patch fixes a memory leak before process exit. Signed-off-by: Stefan Berger --- src/swtpm/common.c | 6 ++++++ src/swtpm/server.c | 4 +++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/swtpm/common.c b/src/swtpm/common.c index e326833..1e28919 100644 --- a/src/swtpm/common.c +++ b/src/swtpm/common.c @@ -921,6 +921,8 @@ static int parse_server_options(char *options, struct server **c) uid_t uid; gid_t gid; + *c = NULL; + ovs = options_parse(options, server_opt_desc, &error); if (!ovs) { logprintf(STDERR_FILENO, "Error parsing server options: %s\n", error); @@ -1011,6 +1013,10 @@ static int parse_server_options(char *options, struct server **c) return 0; error: + if (*c) { + server_free(*c); + *c = NULL; + } option_values_free(ovs); return -1; diff --git a/src/swtpm/server.c b/src/swtpm/server.c index d0d12c8..a57cc84 100644 --- a/src/swtpm/server.c +++ b/src/swtpm/server.c @@ -99,8 +99,10 @@ void server_free(struct server *c) if (c->fd >= 0) close(c->fd); - if (c->sockpath) + if (c->sockpath) { unlink(c->sockpath); + free(c->sockpath); + } free(c); } -- 2.39.5