From 5b108efde4d146ba2fea1c593efcaf1582e7390a Mon Sep 17 00:00:00 2001 From: ridiculousfish Date: Sat, 21 Jan 2017 14:53:29 -0800 Subject: [PATCH] Use unique_ptr in builtin_string Avoids manual calls to delete --- src/builtin_string.cpp | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/builtin_string.cpp b/src/builtin_string.cpp index c0c3a5bdc..f717cef15 100644 --- a/src/builtin_string.cpp +++ b/src/builtin_string.cpp @@ -570,24 +570,22 @@ static int string_match(parser_t &parser, io_streams_t &streams, int argc, wchar return BUILTIN_STRING_ERROR; } - string_matcher_t *matcher; + std::unique_ptr matcher; if (regex) { - matcher = new pcre2_matcher_t(argv[0], pattern, opts, streams); + matcher.reset(new pcre2_matcher_t(argv[0], pattern, opts, streams)); } else { - matcher = new wildcard_matcher_t(argv[0], pattern, opts, streams); + matcher.reset(new wildcard_matcher_t(argv[0], pattern, opts, streams)); } const wchar_t *arg; wcstring storage; while ((arg = string_get_arg(&i, argv, &storage, streams)) != 0) { if (!matcher->report_matches(arg)) { - delete matcher; return BUILTIN_STRING_ERROR; } } int rc = matcher->match_count() > 0 ? BUILTIN_STRING_OK : BUILTIN_STRING_NONE; - delete matcher; return rc; }