76 lines
2.0 KiB
Diff
76 lines
2.0 KiB
Diff
|
|
From ac728c989e6c1e107f332ccdcd38d6e4271cffc3 Mon Sep 17 00:00:00 2001
|
||
|
|
From: huyan <hu.huyan@huawei.com>
|
||
|
|
Date: Mon, 17 Jun 2019 15:16:19 +0800
|
||
|
|
Subject: [PATCH] backport remove resource leaks from device-discovery.c
|
||
|
|
|
||
|
|
---
|
||
|
|
utils/blkmapd/device-discovery.c | 22 +++++++++++++++++++++-
|
||
|
|
1 file changed, 21 insertions(+), 1 deletion(-)
|
||
|
|
|
||
|
|
diff --git a/utils/blkmapd/device-discovery.c b/utils/blkmapd/device-discovery.c
|
||
|
|
index 2ce60f8..e811703 100644
|
||
|
|
--- a/utils/blkmapd/device-discovery.c
|
||
|
|
+++ b/utils/blkmapd/device-discovery.c
|
||
|
|
@@ -186,8 +186,13 @@ static void bl_add_disk(char *filepath)
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
- if (disk && diskpath)
|
||
|
|
+ if (disk && diskpath) {
|
||
|
|
+ if (serial) {
|
||
|
|
+ free(serial->data);
|
||
|
|
+ free(serial);
|
||
|
|
+ }
|
||
|
|
return;
|
||
|
|
+ }
|
||
|
|
|
||
|
|
/* add path */
|
||
|
|
path = malloc(sizeof(struct bl_disk_path));
|
||
|
|
@@ -223,6 +228,10 @@ static void bl_add_disk(char *filepath)
|
||
|
|
disk->size = size;
|
||
|
|
disk->valid_path = path;
|
||
|
|
}
|
||
|
|
+ if (serial) {
|
||
|
|
+ free(serial->data);
|
||
|
|
+ free(serial);
|
||
|
|
+ }
|
||
|
|
}
|
||
|
|
return;
|
||
|
|
|
||
|
|
@@ -232,6 +241,10 @@ static void bl_add_disk(char *filepath)
|
||
|
|
free(path->full_path);
|
||
|
|
free(path);
|
||
|
|
}
|
||
|
|
+ if (serial) {
|
||
|
|
+ free(serial->data);
|
||
|
|
+ free(serial);
|
||
|
|
+ }
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
|
||
|
|
@@ -375,7 +388,12 @@ static void bl_rpcpipe_cb(void)
|
||
|
|
if (event->mask & IN_CREATE) {
|
||
|
|
BL_LOG_WARNING("nfs pipe dir created\n");
|
||
|
|
bl_watch_dir(nfspipe_dir, &nfs_pipedir_wfd);
|
||
|
|
+ if (bl_pipe_fd >= 0)
|
||
|
|
+ close(bl_pipe_fd);
|
||
|
|
bl_pipe_fd = open(bl_pipe_file, O_RDWR);
|
||
|
|
+ if (bl_pipe_fd < 0)
|
||
|
|
+ BL_LOG_ERR("open %s failed: %s\n",
|
||
|
|
+ event->name, strerror(errno));
|
||
|
|
} else if (event->mask & IN_DELETE) {
|
||
|
|
BL_LOG_WARNING("nfs pipe dir deleted\n");
|
||
|
|
inotify_rm_watch(bl_watch_fd, nfs_pipedir_wfd);
|
||
|
|
@@ -388,6 +406,8 @@ static void bl_rpcpipe_cb(void)
|
||
|
|
continue;
|
||
|
|
if (event->mask & IN_CREATE) {
|
||
|
|
BL_LOG_WARNING("blocklayout pipe file created\n");
|
||
|
|
+ if (bl_pipe_fd >= 0)
|
||
|
|
+ close(bl_pipe_fd);
|
||
|
|
bl_pipe_fd = open(bl_pipe_file, O_RDWR);
|
||
|
|
if (bl_pipe_fd < 0)
|
||
|
|
BL_LOG_ERR("open %s failed: %s\n",
|
||
|
|
--
|
||
|
|
1.8.3.1
|
||
|
|
|