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..


In reply to FUSE, fuse_get_context and private = dangling pointer woes by CandyAngel

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.