diff options
author | Sylvestre Gallon <syl@cvs.openbsd.org> | 2013-11-21 22:03:27 +0000 |
---|---|---|
committer | Sylvestre Gallon <syl@cvs.openbsd.org> | 2013-11-21 22:03:27 +0000 |
commit | d7e7c26cc5458dc95607fad0f5e34d5b610cd245 (patch) | |
tree | 74e45e7262b42dcf41b695a37e248e7267ed5f48 /lib | |
parent | a66c695658de5dafeb73f951622c793505708d81 (diff) |
Fix a big memory leak in libfuse.
Spotted by sthen@
With some input from stsp@ and tested by mpk@ and sthen@
ok sthen@, stsp@
Diffstat (limited to 'lib')
-rw-r--r-- | lib/libfuse/fuse_ops.c | 21 |
1 files changed, 10 insertions, 11 deletions
diff --git a/lib/libfuse/fuse_ops.c b/lib/libfuse/fuse_ops.c index 8ec2543b9c6..4f7800922a8 100644 --- a/lib/libfuse/fuse_ops.c +++ b/lib/libfuse/fuse_ops.c @@ -1,4 +1,4 @@ -/* $OpenBSD: fuse_ops.c,v 1.13 2013/10/08 04:57:39 guenther Exp $ */ +/* $OpenBSD: fuse_ops.c,v 1.14 2013/11/21 22:03:26 syl Exp $ */ /* * Copyright (c) 2013 Sylvestre Gallon <ccna.syl@gmail.com> * @@ -276,9 +276,7 @@ ifuse_ops_readdir(struct fuse *f, struct fusebuf *fbuf) size = fbuf->fb_io_len; startsave = 0; - fbuf->fb_dat = malloc(FUSEBUFMAXSIZE); - bzero(fbuf->fb_dat, FUSEBUFMAXSIZE); - + fbuf->fb_dat = malloc(size); vn = tree_get(&f->vnode_tree, fbuf->fb_ino); if (!vn->fd->filled) { @@ -313,6 +311,9 @@ ifuse_ops_readdir(struct fuse *f, struct fusebuf *fbuf) vn->fd->filled = 1; } + if (fbuf->fb_len == 0) + free(fbuf->fb_dat); + return (0); } @@ -427,6 +428,9 @@ ifuse_ops_read(struct fuse *f, struct fusebuf *fbuf) else fbuf->fb_err = ret; + if (fbuf->fb_len == 0) + free(fbuf->fb_dat); + return (0); } @@ -557,15 +561,10 @@ ifuse_ops_readlink(struct fuse *f, struct fusebuf *fbuf) ret = -ENOSYS; free(realname); - if (!ret) - len = strnlen(name, PATH_MAX); - else - len = -1; - - fbuf->fb_len = len + 1; fbuf->fb_err = ret; - if (!ret) { + len = strnlen(name, PATH_MAX); + fbuf->fb_len = len + 1; fbuf->fb_dat = malloc(fbuf->fb_len); memcpy(fbuf->fb_dat, name, len); fbuf->fb_dat[len] = '\0'; |