Skip to content

Commit 4bc2e72

Browse files
committed
Avoid unlink call on empty string
Replaced move constructor by "swap" on default-constructed, empty string. This because the std::string move constructor does not guarantee that the moved string is actually erased. Also added test so we don't unnecessarily call "unlink" on an empty string, even though this has no effect.
1 parent 839394d commit 4bc2e72

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

src/util/tempfile.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,5 +164,5 @@ Function: temporary_filet::~temporary_filet
164164

165165
temporary_filet::~temporary_filet()
166166
{
167-
unlink(name.c_str());
167+
if(!name.empty()) unlink(name.c_str());
168168
}

src/util/tempfile.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,9 @@ class temporary_filet
3232
// Using the copy constructor would delete the file twice.
3333
temporary_filet(const temporary_filet &)=delete;
3434

35-
temporary_filet(temporary_filet &&other) :
36-
name(std::move(other.name))
35+
temporary_filet(temporary_filet &&other)
3736
{
37+
name.swap(other.name);
3838
}
3939

4040
// get the name

0 commit comments

Comments
 (0)