diff --git a/ext/re2/re2.cc b/ext/re2/re2.cc index 89bcba5..4b23de4 100644 --- a/ext/re2/re2.cc +++ b/ext/re2/re2.cc @@ -1589,6 +1589,12 @@ static VALUE re2_set_add(VALUE self, VALUE pattern) { int index = s->set->Add(regex, &err); if (index < 0) { + char msg[100]; + snprintf(msg, sizeof(msg), "str rejected by RE2::Set->Add(): %s", + err.c_str()); + + /* Manually destruct the error string before we throw an exception. */ + err.~basic_string(); rb_raise(rb_eArgError, "str rejected by RE2::Set->Add(): %s", err.c_str()); }