Skip to content

Commit

Permalink
make sure to disable profiler even if exceptions are raised
Browse files Browse the repository at this point in the history
  • Loading branch information
tmm1 committed Sep 18, 2012
1 parent 899894d commit e302499
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions ext/rblineprof.c
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,13 @@ summarize_files(st_data_t key, st_data_t record, st_data_t arg)
return ST_CONTINUE;
}

static VALUE
lineprof_ensure(VALUE self)
{
rb_remove_event_hook(profiler_hook);
rblineprof.enabled = false;
}

VALUE
lineprof(VALUE self, VALUE filename)
{
Expand Down Expand Up @@ -182,9 +189,7 @@ lineprof(VALUE self, VALUE filename)

rblineprof.enabled = true;
rb_add_event_hook(profiler_hook, RUBY_EVENT_LINE);
rb_yield(Qnil);
rb_remove_event_hook(profiler_hook);
rblineprof.enabled = false;
rb_ensure(rb_yield, Qnil, lineprof_ensure, self);

VALUE ret = rb_hash_new();
VALUE ary = Qnil;
Expand Down

0 comments on commit e302499

Please sign in to comment.