Skip to content
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

Closed
Stevie-O opened this issue Mar 1, 2017 · 1 comment · Fixed by #661
Closed

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

Stevie-O opened this issue Mar 1, 2017 · 1 comment · Fixed by #661
Milestone

Comments

@Stevie-O
Copy link
Contributor

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]); });
@Stevie-O
Copy link
Contributor Author

Stevie-O commented Mar 1, 2017

I have created a pull request with the fix: 661

@Stevie-O Stevie-O mentioned this issue Mar 1, 2017
ailin-nemui added a commit that referenced this issue Mar 2, 2017
Fix Segfault when unloading a script that registers for 'script destroyed' signals

Closes #660
@ailin-nemui ailin-nemui added this to the 1.1.0 milestone Jun 26, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants