From 752b5362eef966e6b6973afd18668ae47a7ee67f Mon Sep 17 00:00:00 2001 From: Fabian Homborg Date: Mon, 13 May 2019 21:15:58 +0200 Subject: [PATCH] Only widen string if necessary This tried a bunch of times, but only the final one is important. --- src/env_universal_common.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/env_universal_common.cpp b/src/env_universal_common.cpp index 39d7831d8..ad8867384 100644 --- a/src/env_universal_common.cpp +++ b/src/env_universal_common.cpp @@ -511,16 +511,18 @@ bool env_universal_t::open_temporary_file(const wcstring &directory, wcstring *o int saved_errno; const wcstring tmp_name_template = directory + L"/fishd.tmp.XXXXXX"; + char *narrow_str = nullptr; for (size_t attempt = 0; attempt < 10 && !success; attempt++) { - char *narrow_str = wcs2str(tmp_name_template); + narrow_str = wcs2str(tmp_name_template); int result_fd = fish_mkstemp_cloexec(narrow_str); saved_errno = errno; success = result_fd != -1; *out_fd = result_fd; - *out_path = str2wcstring(narrow_str); - free(narrow_str); } + *out_path = str2wcstring(narrow_str); + free(narrow_str); + if (!success) { const char *error = std::strerror(saved_errno); debug(0, _(L"Unable to open temporary file '%ls': %s"), out_path->c_str(), error);