1
0
mirror of git://sourceware.org/git/lvm2.git synced 2024-12-21 13:34:40 +03:00

libdaemon: Fix some client leaks.

Free (and clear) h.protocol string on daemon_open() error paths
so it's OK for caller to skip calling daemon_close() if returned
h.socket_fd is -1.

Close h.socket_fd in daemon_close() to avoid possible leak.

https://bugzilla.redhat.com/1164234
This commit is contained in:
Alasdair G Kergon 2014-11-28 21:31:51 +00:00
parent 530ebd8976
commit 6521c4b215
4 changed files with 31 additions and 11 deletions

View File

@ -1,5 +1,6 @@
Version 2.02.114 -
=====================================
Release socket in daemon_close and protocol string in a daemon_open error path.
Add --cachepolicy and --cachesettings to lvcreate.
Fix regression when parsing /dev/mapper dir (2.02.112).
Fix missing rounding to 64KB when estimating optimal thin pool chunk size.

View File

@ -105,6 +105,7 @@ void _dump_vg(daemon_handle h, const char *uuid)
int main(int argc, char **argv) {
daemon_handle h = lvmetad_open();
/* FIXME Missing error path */
if (argc > 1) {
int i;
@ -114,6 +115,7 @@ int main(int argc, char **argv) {
scan(h, argv[i]);
}
destroy_toolcontext(cmd);
/* FIXME Missing lvmetad_close() */
return 0;
}
@ -122,6 +124,6 @@ int main(int argc, char **argv) {
_dump_vg(h, vgid);
_pv_add(h, uuid3, NULL);
daemon_close(h);
daemon_close(h); /* FIXME lvmetad_close? */
return 0;
}

View File

@ -26,7 +26,11 @@
daemon_handle daemon_open(daemon_info i)
{
daemon_handle h = { .protocol_version = 0, .error = 0 };
daemon_handle h = {
.protocol = NULL,
.protocol_version = 0,
.error = 0
};
daemon_reply r = { 0 };
struct sockaddr_un sockaddr = { .sun_family = AF_UNIX };
@ -79,12 +83,16 @@ daemon_handle daemon_open(daemon_info i)
return h;
error:
if (h.socket_fd >= 0)
if (close(h.socket_fd))
log_sys_error("close", "daemon_open");
if (h.socket_fd >= 0 && close(h.socket_fd))
log_sys_error("close", "daemon_open");
h.socket_fd = -1;
if (r.cft)
daemon_reply_destroy(r);
h.socket_fd = -1;
dm_free((char *)h.protocol);
h.protocol = NULL;
return h;
}
@ -118,7 +126,8 @@ daemon_reply daemon_send(daemon_handle h, daemon_request rq)
return reply;
}
void daemon_reply_destroy(daemon_reply r) {
void daemon_reply_destroy(daemon_reply r)
{
if (r.cft)
dm_config_destroy(r.cft);
buffer_destroy(&r.buffer);
@ -160,6 +169,12 @@ daemon_reply daemon_send_simple(daemon_handle h, const char *id, ...)
void daemon_close(daemon_handle h)
{
if (h.socket_fd >= 0) {
log_debug("Closing daemon socket (fd %d).", h.socket_fd);
if (close(h.socket_fd))
log_sys_error("close", "daemon_close");
}
dm_free((char *)h.protocol);
}
@ -210,7 +225,8 @@ int daemon_request_extend(daemon_request r, ...)
return res;
}
void daemon_request_destroy(daemon_request r) {
void daemon_request_destroy(daemon_request r)
{
if (r.cft)
dm_config_destroy(r.cft);
buffer_destroy(&r.buffer);

View File

@ -97,15 +97,16 @@ void daemon_request_destroy(daemon_request r);
void daemon_reply_destroy(daemon_reply r);
static inline int64_t daemon_reply_int(daemon_reply r, const char *path, int64_t def) {
static inline int64_t daemon_reply_int(daemon_reply r, const char *path, int64_t def)
{
return dm_config_find_int64(r.cft->root, path, def);
}
static inline const char *daemon_reply_str(daemon_reply r, const char *path, const char *def) {
static inline const char *daemon_reply_str(daemon_reply r, const char *path, const char *def)
{
return dm_config_find_str_allow_empty(r.cft->root, path, def);
}
/* Shut down the communication to the daemon. Compulsory. */
void daemon_close(daemon_handle h);