Names "A" and "B" are used for simplicity. I didn't use them in real codes.

The following gives short enough but clear code samples that result in 1 warning and 1 error messages that confused me.


1. "Attempt to free unreferenced scalar" warning.
for simplicity, there are 2 perl script files: test.pl and test.pm.
_test.pl_
use threads; use test; my $argument=1; my $thread=threads->create("forthread", ($argument)); $thread->join(); exit(0);

_test.pm_
package test; require Exporter; our @ISA =qw(Exporter); our @EXPORT =qw(queuereader); our @VERSION =1.0; sub forthread{ my ($arg)=@_; return 0; } #forthread

NOTE: there is no problem if "forthread" is in test.pl. But when we put "forthread" in a separate file other than the caller file, it reports the above warning message, in fact, no matter if we pass any argument at time of thread creation.


2. "Scalar leaked:1" error.
It is for simplicity that bareword "argument" is used in place of any type of variable.
_test.pl_
use threads; use test; my $thread=threads->create("forthread", (argument)); $thread->join(); exit(0);

-test.pm_
package test; require Exporter; our @ISA =qw(Exporter); our @EXPORT =qw(queuereader); our @VERSION =1.0; sub forthread{ my (argument)=@_; my $thread=threads->create("another", (argument)); $thread->join(); return 0; } #forthread sub another{ return 0; } #another

NOTE: the error is reported when "argument" is one of the following:
- reference to scalar
- reference to array
- reference to hash
- hash


In reply to Re^2: "Attempt to free unreferenced scalar" and "Scalars leaked: 1" ? by licht
in thread "Attempt to free unreferenced scalar" and "Scalars leaked: 1" ? by licht

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.