deadpickle has asked for the wisdom of the Perl Monks concerning the following question:

I am getting the following errors when I exit my program. They dont point to any specific line so I dont know how to fix them. Is there a way to debug these errors?
GLib-GObject-CRITICAL **: g_object_steal_qdata: assertion `G_IS_OBJECT + (object)' failed during global destruction. GLib-GObject-CRITICAL **: g_object_unref: assertion `G_IS_OBJECT (obje +ct)' faile d during global destruction. GLib-GObject-CRITICAL **: g_object_steal_qdata: assertion `G_IS_OBJECT + (object)' failed, <GEN4> line 9 during global destruction. GLib-GObject-CRITICAL **: g_object_unref: assertion `G_IS_OBJECT (obje +ct)' faile d, <GEN4> line 9 during global destruction.

Replies are listed 'Best First'.
Re: Glib Errors on close
by Joost (Canon) on Feb 16, 2008 at 19:13 UTC
      using the perl debugger I found a little bit about the problem. The output I received seems to be possibly from the thread:

      Attempt to free unreferenced scalar: SV 0x43314ac, Perl interpreter: 0x41083fc a t GRRUVI-v0.45.pl line 133. at GRRUVI-v0.45.pl line 133
      Attempt to free unreferenced scalar: SV 0x5f53f6c, Perl interpreter: 0x4c9c85c a t GRRUVI-v0.45.pl line 134.
      at GRRUVI-v0.45.pl line 134 GLib-GObject-CRITICAL **: g_object_steal_qdata: assertion `G_IS_OBJECT (object)' failed during global destruction. at GRRUVI-v0.45.pl line 0 eval {...} called at GRRUVI-v0.45.pl line 0
      GLib-GObject-CRITICAL **: g_object_unref: assertion `G_IS_OBJECT (object)' faile d during global destruction. at GRRUVI-v0.45.pl line 0

      and refers to the code lines:

      ################################################# #Threads my $thread_gps = threads->new( \&gps); my $thread_sftp = threads->new( \&sftp); #################################################
      though the output is a little strange with it referring to line zero of the program. The threads are stopped by the join command. I wonder if the threads I have are being exited incorrectly? I'm not sure what this attempt to free unreferenced scalar is?!

      ####################Threads#################### #-------------------GPS------------------- sub gps { my $gps_device; while (1) { goto END if $die == 1; if ($gps_start == 1) { $gps_device = GPS::NMEA->new(Port => $gps, Baud => 4800); for (;;) { #stops the warnings in the GPS device module local $^W = 0; ($ns,$lat,$ew,$lon) = $gps_device->get_position; goto END if $die == 1; last if $gps_start == 0; sleep 3; } undef $gps_device; } else {sleep 4} } END: } #-------------------SFTP------------------- sub sftp{ $|++; while(1){ if ( $die == 1 ){ goto END }; if ( $sftp_start == 1 ) { my $seconds = 120; my %args = (host=>$server, user=>$username, timeout=>$seco +nds); my $sftp = Net::SFTP::Foreign->new(%args); #$error = 1 if $sftp->error; for (;;) { if (defined $ns){ #The GPS file Functions my $gps_loc = $sftp->open( "$gps_remote/$gps_file" + , SSH2_FXF_CREAT|SSH2_FXF_WRITE) or $sftp->error; my $new_lat; my $new_lon; #adjust the gps position into decimal if ($ns eq 'S'){ $new_lat = "-$lat"; } else { $new_lat = $lat; } if ($ew eq 'W'){ $new_lon = "-$lon"; } else { $new_lon = $lon; } $sftp->write( $gps_loc, "$nick $new_lat $new_lon") +; $sftp->close( $gps_loc); } #VC Base if ($job == 2) { #Upload the uasposition file $sftp->put( $uasposition_local, $uasposition_remot +e); #update the counter $count_uasposition = $count_uasposition + 0.05; #Create the attribute file my $stat_final = Net::SFTP::Foreign::Attributes->n +ew; #open the files on the server; flagged for writing + and creating my $waytemp = $sftp->open( $waytemp_remote) or $sf +tp->error; my $wayfinal = $sftp->open( $wayfinal_remote, SSH2 +_FXF_CREAT, $stat_final) or $sftp->error; #Read the stats of the files and check which is ne +wer my $stat_temp = $sftp->fstat($waytemp); $stat_final = $sftp->fstat($wayfinal); #check to see if temp is newer than final if (( $stat_final->mtime) < ($stat_temp->mtime)) { #Turn verification window on $verify = 1 if $verify == 0; if ( $verify == 2) { #read the lines in then write to the wayfi +nal file if it is newer then the waytemp file my $print = $sftp->readline( $waytemp); my $wayfinal = $sftp->open( $wayfinal_remo +te, SSH2_FXF_TRUNC|SSH2_FXF_WRITE) or $sftp->error; #write to the file and add to the counter +if it does write $sftp->write( $wayfinal, $print); $count_waypoint = $count_waypoint + 0.05; $verify = 0; } if ( $verify == 3) { #get time and print it to the final file my $time = time; $stat_final->set_amtime( $time, $time); $sftp->fsetstat( $wayfinal, $stat_final); $count_waypoint = $count_waypoint + 0.05; $verify = 0; } #close the files on the server $sftp->close( $waytemp); $sftp->close( $wayfinal); } } #Met Base if ($job == 3){ #Open the waytemp file on the server; for write on +ly if ( $verify == 4) { my $waytemp = $sftp->open( $waytemp_remote, SS +H2_FXF_TRUNC|SSH2_FXF_WRITE) or $sftp->error; #Write the waypoints to the waytemp file $sftp->write( $waytemp, $coords); $sftp->close( $waytemp); $count_waypoint = $count_waypoint + 0.05; $verify = 0; } } sleep 1; } if($sftp_start == 0){ last}; if($die == 1){ goto END }; #undef $sftp; }else { sleep 1 } } END: } #################################################
        An "attempt to free unreferenced scalar" basically means the perl interpreter got confused somewhere about the reference count of some object. This usually indicates a serious issue with either the interpreter itself or some of the XS/C based extensions you're using.

        Given that you're using threads, it really could be either, but I would probably start by not using threads and see if the problem goes away. There really aren't many situations where threads are the best option (at least, not in perl).

Re: Glib Errors on close
by plobsing (Friar) on Feb 16, 2008 at 18:06 UTC
    What are you doing in your program?

    What modules are you using?

    How is your perl configured?

    How do you expect us to fix anything with almost no information?

    It looks like you are having some errors at the C/XS level. There are tools for dealing with this such as gdb and valgrind.

    But I'm just guessing here. It could also be that you are mixing eventloops or using threads with something that doesn't play nice with threads.
Re: Glib Errors on close
by zentara (Cardinal) on Feb 17, 2008 at 17:28 UTC
    Have you tried putting
    Glib::Object->set_threadsafe (TRUE);
    at the top of your code?

    If that dosn't do it, you are probably setting up your threads improperly, and you need to show a complete working snippet to demonstrate the problem. Gtk2 tries to be better at thread clean-up than Tk, BUT it is not perfect. If you try to dynamically create threads from anywhere in your program, you are quite likely to hit problems. Your thread code contains some complex ssh and sftp code, and they may not be threadsafe, or you need to do cleanup on the ssh/sftp connection before closing the thread. Try putting simpler code in the sftp thread sub, and see if it works. Like just connect, get a dirlist, and disconnect. If it works, then start adding complexity and testing as you go.


    I'm not really a human, but I play one on earth. Cogito ergo sum a bum