On Mon, Jul 15, 2013 at 07:36:50PM +0800, Wang Shilong wrote: > valgrind complains open_file_or_dir() causes a memory leak.That is because > if we open a directoy by opendir(), and then we should call closedir() > to free memory.
I've reviewed this and don't see a better way how to fix the leaks now. One comment below, otherwise ok, thanks. > --- a/cmds-filesystem.c > +++ b/cmds-filesystem.c > @@ -91,9 +89,8 @@ static int cmd_df(int argc, char **argv) > sargs = realloc(sargs, sizeof(struct btrfs_ioctl_space_args) + > (count * sizeof(struct btrfs_ioctl_space_info))); > if (!sargs) { > - close(fd); > - free(sargs_orig); > - return -ENOMEM; > + ret = -ENOMEM; > + goto out; sargs_orig is leaked here, the out: block only frees sargs, but it's null now, so sargs = sargs_orig; goto out; should fix it. > } > > sargs->space_slots = count; -- To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html