summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Menges <christian.menges@tum.de>2021-05-09 12:12:01 +0200
committerGitHub <noreply@github.com>2021-05-09 11:12:01 +0100
commit7d1ba6b066cee563e1b52f712146bd2b322ef2ef (patch)
tree92f9abf9c618515414af7f9c9e5335258c9ecd8b
parent995d46a205faba0fa81bded8a6d48dd533b69b57 (diff)
downloadfuse-7d1ba6b066cee563e1b52f712146bd2b322ef2ef.tar.gz
Fix memory leaks in examples (#604)
-rw-r--r--example/passthrough_hp.cc6
-rw-r--r--example/passthrough_ll.c12
2 files changed, 17 insertions, 1 deletions
diff --git a/example/passthrough_hp.cc b/example/passthrough_hp.cc
index 3e11266..e976166 100644
--- a/example/passthrough_hp.cc
+++ b/example/passthrough_hp.cc
@@ -1126,7 +1126,11 @@ static cxxopts::ParseResult parse_options(int argc, char **argv) {
fs.debug = options.count("debug") != 0;
fs.nosplice = options.count("nosplice") != 0;
- fs.source = std::string {realpath(argv[1], NULL)};
+ char* resolved_path = realpath(argv[1], NULL);
+ if (resolved_path == NULL)
+ warn("WARNING: realpath() failed with");
+ fs.source = std::string {resolved_path};
+ free(resolved_path);
return options;
}
diff --git a/example/passthrough_ll.c b/example/passthrough_ll.c
index 0e7535c..8fdf887 100644
--- a/example/passthrough_ll.c
+++ b/example/passthrough_ll.c
@@ -171,6 +171,17 @@ static void lo_init(void *userdata,
}
}
+static void lo_destroy(void *userdata)
+{
+ struct lo_data *lo = (struct lo_data*) userdata;
+
+ while (lo->root.next != &lo->root) {
+ struct lo_inode* next = lo->root.next;
+ lo->root.next = next->next;
+ free(next);
+ }
+}
+
static void lo_getattr(fuse_req_t req, fuse_ino_t ino,
struct fuse_file_info *fi)
{
@@ -1113,6 +1124,7 @@ static void lo_lseek(fuse_req_t req, fuse_ino_t ino, off_t off, int whence,
static const struct fuse_lowlevel_ops lo_oper = {
.init = lo_init,
+ .destroy = lo_destroy,
.lookup = lo_lookup,
.mkdir = lo_mkdir,
.mknod = lo_mknod,