CandyAngel has asked for the wisdom of the Perl Monks concerning the following question:
I'm looking into using FUSE for a quick project but I have come across, what I think is, a major issue.
With the FUSE module, you can provide an 'init' callback where you can return a scalar to be put into fuse_get_context() as 'private'. I want to use this to store the scripts "main" object so I can access the information needed to respond to the various calls (getattr, read, write etc.).
However, as soon as I try to use get_fuse_context with this, Perl gives me a lot of various errors like "Attempt to copy freed scalar" and "Attempt to free unreferenced scalar" and eventually panic-exits. Printing out fuse_get_context with Data::Dumper, shows that the private key is a "dangling pointer" (sorry, I'm not sure if this is the actual term).
It looks as though when fuse_get_context is called, it copies the structure in such a way that the refcount is not increased, so when it exits scope, it is being freed despite still being in use (it works okay the first time, as shown below).
I think this is the minimal code to reproduce the problem:
#!/usr/bin/env perl use strict; use warnings; use Fuse; my $priv_data = 'PRIVDAT'; Fuse::main ( debug => 1, init => sub { return $priv_data }, mountpoint => 'mnt', getattr => sub { Fuse::fuse_get_context(); return qw[0 0 0040700 1 0 0 0 0 0 0 0 4096 0] }, );
(making $priv_data a global was just to make sure it was always in a scope)
On the fuller code where more callbacks are implemented, it results in values like this:
$ fuse_init_unref.pl | grep private 'private' => 'PRIVDAT' 'private' => 2, 'private' => 0 'private' => ' => ', 'private' => 0, 'private' => [ 'private' => undef, 'private' => undef, 'private' => undef, 'private' => '',
Any ideas of whether it is FUSE or myself at fault? The only workarounds I can think of would involve wrapping all the callbacks so I can inject the object or having singletons..
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: FUSE, fuse_get_context and private = dangling pointer woes
by thanos1983 (Parson) on Oct 09, 2014 at 23:48 UTC | |
by CandyAngel (Initiate) on Oct 10, 2014 at 08:22 UTC | |
by thanos1983 (Parson) on Oct 11, 2014 at 01:31 UTC | |
by Anonymous Monk on Oct 11, 2014 at 02:01 UTC | |
by thanos1983 (Parson) on Oct 11, 2014 at 10:57 UTC | |
|