New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Segfault when unloading a script that registers for 'script destroyed' signals #660

Stevie-O opened this Issue Mar 1, 2017 · 1 comment


None yet
1 participant

Stevie-O commented Mar 1, 2017

Script unloading is done in the wrong order:

  1. Destroy the Perl package for the script
  2. Emit 'signal destroyed' signal
  3. Unhook signal handlers for the script

If a script adds a 'script destroyed' signal handler, unloading the script will cause step 2 to attempt to invoke the 'signal destroyed' handler in the script (because the signal handlers aren't yet removed). However, because the Perl package has been destroyed, this will cause a script error, which will in turn attempt to unload the script (again). This will continue recursively until either stack or heap space is exhausted and the program segfaults.

To reproduce, simply load this script, then unload it:

use strict;
use Irssi qw/signal_add signal_register active_win/;
use Data::Dumper;

signal_register({ 'script error' => [ 'Irssi::Script', 'string' ] });
signal_register({ 'script created' => [ 'Irssi::Script' ] });
signal_register({ 'script destroyed' => [ 'Irssi::Script' ] });

sub scriptevent {
eval {
	active_win->command("SAY ScriptEvent: ($_[0]) $_[1]{package}");

signal_add('script error', sub { scriptevent('script error', $_[0]); });
signal_add('script created', sub { scriptevent('script created', $_[0]); });
signal_add('script destroyed', sub { scriptevent('script destroyed', $_[0]); });

This comment has been minimized.


Stevie-O commented Mar 1, 2017

I have created a pull request with the fix: 661

@Stevie-O Stevie-O referenced this issue Mar 1, 2017


Fix for #660 #661

ailin-nemui added a commit that referenced this issue Mar 2, 2017

Merge pull request #661 from Stevie-O/master
Fix Segfault when unloading a script that registers for 'script destroyed' signals

Closes #660
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment