Skip to content

Commit c412e95

Browse files
committed
Add a copy constructor to InvalidSass exception
The copy constructor transfers the ownership of `owned_src` from `rhs` to `lhs`. Otherwise, `owned_src` may be destroyed too early and more than once. In the libsass codebase, this copy can only happen on `throw`. Modern compilers elide such copies. In our CI, only VS 2013 does not.
1 parent ef56d81 commit c412e95

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

src/error_handling.hpp

+5
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,11 @@ namespace Sass {
3737

3838
class InvalidSass : public Base {
3939
public:
40+
InvalidSass(InvalidSass& other) : Base(other) {
41+
// Assumes that `this` will outlive `other`.
42+
owned_src = other.owned_src;
43+
other.owned_src = nullptr;
44+
}
4045
InvalidSass(ParserState pstate, Backtraces traces, std::string msg, char* owned_src = nullptr);
4146
virtual ~InvalidSass() throw() { sass_free_memory(owned_src); };
4247
char *owned_src;

0 commit comments

Comments
 (0)