eden: fixup how we construct the fuse args struct

Summary:
I found this by running the tests with ASAN enabled; it was reporting leaks.

The issue is that fuse decides to append some args to the argument list in some
cases.  When it does this it tries to realloc the storage in the argv array.
This was not safe to do because that data was owned by the vector and may not
have been allocated directly by malloc.

This diff switches us to use the underlying functions in libfuse that append
arguments and then know how to safely free the result.

SCOPE_EXIT is used to ensure that this gets cleaned up when we return.

Reviewed By: bolinfest

Differential Revision: D3519999

fbshipit-source-id: ca12739f11be1fd9662063ec7515cec90ccf0d57
This commit is contained in:
Wez Furlong 2016-07-05 17:41:38 -07:00 committed by Facebook Github Bot 6
parent 10a9b86fc7
commit c55ed3dee4

View File

@ -1044,15 +1044,24 @@ std::unique_ptr<fuse_session, SessionDeleter> Dispatcher::makeSession(
bool debug) {
chan_ = &channel;
// libfuse may decide to mutate these arguments when we call fuse_lowlevel_new
// so we use fuse_opt_add_arg() to mutate it. Start with a well-defined
// initial state.
fuse_args fargs{0, nullptr, 0};
std::vector<const char*> fuseArgs = {
"fuse", "-o", "allow_root",
SCOPE_EXIT {
// Ensure that the allocations associated with fargs are released when
// we exit this function.
fuse_opt_free_args(&fargs);
};
// Each of these calls will duplicate the input string and expand the storage
// in fargs.
fuse_opt_add_arg(&fargs, "fuse");
fuse_opt_add_arg(&fargs, "-o");
fuse_opt_add_arg(&fargs, "allow_root");
if (debug) {
fuseArgs.push_back("-d");
fuse_opt_add_arg(&fargs, "-d");
}
fargs.argc = fuseArgs.size();
fargs.argv = const_cast<char**>(fuseArgs.data());
auto sess =
fuse_lowlevel_new(&fargs, &dispatcher_ops, sizeof(dispatcher_ops), this);