--- a/libregex/op_regex.cpp
+++ b/libregex/op_regex.cpp
@@ -28,8 +28,9 @@
 	size_t needed_size = regerror(err, &regexp, 0, 0);
 	char * buffer = new char[needed_size];
 	regerror(err, &regexp, buffer, needed_size);
-
-	return buffer;
+	string retval = buffer;
+	delete [] buffer;
+	return retval;
 }