Marcus Harnisch <[EMAIL PROTECTED]> writes: >Hi List, > >A couple of days ago, I received a bug report relating to my >Unix::Syslog module (see CPAN for details). > >The user noticed that the following code > > openlog( basename($0), LOG_PID, LOG_DAEMON ); > syslog( LOG_DEBUG, 'this is test %d', 1 ); > closelog(); > >would result in > Nov 27 12:37:13 <his machine> 8�^P^H^C[17913]: this is test 1 > >, whereas > > my $ident = basename($0); > > openlog( $ident, LOG_PID, LOG_DAEMON ); > syslog( LOG_DEBUG, 'this is test %d', 1 ); > closelog(); > > Nov 27 12:44:27 <his machine> writelog[17913]: this is test 1 > > >I tracked that bug down to the return value/argument handling and >found that if I copied the ident-string in my openlog() wrapper, >everything worked fine. > >There are three questions now: > >1. Why is the return value (the pointer) of a function being reused?
I suspect the problem is that openlog() is not taking a copy of the (mortal) string argument passed nor incrementing its REFCNT. This is just a stack slot so unless perl knows what is going on it will re-use the SV - typicaly doing so at the end of the "statement". > >2. Can this be considered a bug in Perl. Has it been fixed in recent > versions, I am using 5.005_02? It can be considered a bug in Unix::Syslog > >3. To work around that issue, I strdup() the ident-argument before > calling openlog(). Is this The Right Thing(tm)? The perl-ish way is savepvn() rather then the un-portable strdup(), or incrementing the REFCNT of the SV or saving a private SV. > >Best regards, > Marcus -- Nick Ing-Simmons http://www.ni-s.u-net.com/
