swtpm: fix memory leak related to tpmstate directory

This patch fixes a memory leak before process exit.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
This commit is contained in:
Stefan Berger 2018-08-09 10:13:46 -04:00
parent 9c8202ed79
commit fc36ef35ea
5 changed files with 12 additions and 0 deletions

View File

@ -1298,6 +1298,7 @@ static void ptm_cleanup(void)
{
pidfile_remove();
log_global_free();
tpmstate_global_free();
}
static const struct cuse_lowlevel_ops clops = {

View File

@ -66,6 +66,7 @@
#include "utils.h"
#include "mainloop.h"
#include "ctrlchannel.h"
#include "tpmstate.h"
/* local variables */
static int notify_fd[2] = {-1, -1};
@ -178,6 +179,7 @@ static void swtpm_cleanup(struct ctrlchannel *cc, struct server *server)
ctrlchannel_free(cc);
server_free(server);
log_global_free();
tpmstate_global_free();
}
int swtpm_main(int argc, char **argv, const char *prgname, const char *iface)

View File

@ -69,6 +69,7 @@
#ifdef WITH_VTPM_PROXY
#include "vtpm_proxy.h"
#endif
#include "tpmstate.h"
/* local variables */
static int notify_fd[2] = {-1, -1};
@ -199,6 +200,7 @@ static void swtpm_cleanup(struct ctrlchannel *cc)
pidfile_remove();
ctrlchannel_free(cc);
log_global_free();
tpmstate_global_free();
}
int swtpm_chardev_main(int argc, char **argv, const char *prgname, const char *iface)

View File

@ -60,6 +60,12 @@ int tpmstate_set_dir(char *tpmstatedir)
return 0;
}
void tpmstate_global_free(void)
{
free(g_tpmstatedir);
g_tpmstatedir = NULL;
}
const char *tpmstate_get_dir(void)
{
if (g_tpmstatedir)

View File

@ -44,5 +44,6 @@ int tpmstate_set_dir(char *tpmstatdir);
const char *tpmstate_get_dir(void);
int tpmstate_set_mode(mode_t mode);
mode_t tpmstate_get_mode(void);
void tpmstate_global_free(void);
#endif /* _SWTPM_TPMSTATE_H_ */