From 754b0e9b916b5befa2671d0144b52a9d53683996 Mon Sep 17 00:00:00 2001 From: ridiculousfish Date: Sat, 21 Jan 2017 15:47:12 -0800 Subject: [PATCH] Use unique_ptr in string_replace() Eliminates some 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 8860d8d9d..fc27df8fa 100644 --- a/src/builtin_string.cpp +++ b/src/builtin_string.cpp @@ -804,24 +804,22 @@ static int string_replace(parser_t &parser, io_streams_t &streams, int argc, wch return BUILTIN_STRING_ERROR; } - string_replacer_t *replacer; + std::unique_ptr replacer; if (regex) { - replacer = new regex_replacer_t(argv[0], pattern, replacement, opts, streams); + replacer = make_unique(argv[0], pattern, replacement, opts, streams); } else { - replacer = new literal_replacer_t(argv[0], pattern, replacement, opts, streams); + replacer = make_unique(argv[0], pattern, replacement, opts, streams); } const wchar_t *arg; wcstring storage; while ((arg = string_get_arg(&i, argv, &storage, streams)) != 0) { if (!replacer->replace_matches(arg)) { - delete replacer; return BUILTIN_STRING_ERROR; } } int rc = replacer->replace_count() > 0 ? BUILTIN_STRING_OK : BUILTIN_STRING_NONE; - delete replacer; return rc; }