From: luzhipeng <luzhipeng@cestc.cn>
To: qemu-devel <qemu-devel@nongnu.org>
Cc: michael.roth@amd.com, Konstantin Kostiuk <kkostiuk@redhat.com>,
lu zhipeng <luzhipeng@cestc.cn>
Subject: [PATCH] qga: fix possible memory leak
Date: Wed, 21 Sep 2022 22:20:36 +0800 [thread overview]
Message-ID: <20220921142036.1758-1-luzhipeng@cestc.cn> (raw)
From: lu zhipeng <luzhipeng@cestc.cn>
Signed-off-by: lu zhipeng <luzhipeng@cestc.cn>
---
qga/main.c | 19 ++++++++++++++-----
1 file changed, 14 insertions(+), 5 deletions(-)
diff --git a/qga/main.c b/qga/main.c
index 5f1efa2333..73ea1aae65 100644
--- a/qga/main.c
+++ b/qga/main.c
@@ -1287,7 +1287,7 @@ static GAState *initialize_agent(GAConfig *config, int socket_activation)
if (g_mkdir_with_parents(config->state_dir, S_IRWXU) == -1) {
g_critical("unable to create (an ancestor of) the state directory"
" '%s': %s", config->state_dir, strerror(errno));
- return NULL;
+ goto failed;
}
#endif
@@ -1312,7 +1312,7 @@ static GAState *initialize_agent(GAConfig *config, int socket_activation)
if (!log_file) {
g_critical("unable to open specified log file: %s",
strerror(errno));
- return NULL;
+ goto failed;
}
s->log_file = log_file;
}
@@ -1323,7 +1323,7 @@ static GAState *initialize_agent(GAConfig *config, int socket_activation)
s->pstate_filepath,
ga_is_frozen(s))) {
g_critical("failed to load persistent state");
- return NULL;
+ goto failed;
}
config->blacklist = ga_command_blacklist_init(config->blacklist);
@@ -1344,7 +1344,7 @@ static GAState *initialize_agent(GAConfig *config, int socket_activation)
#ifndef _WIN32
if (!register_signal_handlers()) {
g_critical("failed to register signal handlers");
- return NULL;
+ goto failed;
}
#endif
@@ -1357,12 +1357,21 @@ static GAState *initialize_agent(GAConfig *config, int socket_activation)
s->wakeup_event = CreateEvent(NULL, TRUE, FALSE, TEXT("WakeUp"));
if (s->wakeup_event == NULL) {
g_critical("CreateEvent failed");
- return NULL;
+ goto failed;
}
#endif
ga_state = s;
return s;
+
+failed:
+ g_free(s->pstate_filepath);
+ g_free(s->state_filepath_isfrozen);
+ if (s->log_file && s->log_file != stderr) {
+ fclose(s->log_file);
+ }
+ g_free(s);
+ return NULL;
}
static void cleanup_agent(GAState *s)
--
2.31.1
next reply other threads:[~2022-09-21 14:30 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-09-21 14:20 luzhipeng [this message]
2022-09-21 14:53 ` [PATCH] qga: fix possible memory leak Markus Armbruster
2022-09-22 7:39 ` Konstantin Kostiuk
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20220921142036.1758-1-luzhipeng@cestc.cn \
--to=luzhipeng@cestc.cn \
--cc=kkostiuk@redhat.com \
--cc=michael.roth@amd.com \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).