Commit b63867bd authored by Marius Wachtler's avatar Marius Wachtler

fix memory leak

parent dff7b960
...@@ -250,13 +250,11 @@ extern "C" Box* strMul(BoxedString* lhs, Box* rhs) { ...@@ -250,13 +250,11 @@ extern "C" Box* strMul(BoxedString* lhs, Box* rhs) {
// TODO: use createUninitializedString and getWriteableStringContents // TODO: use createUninitializedString and getWriteableStringContents
int sz = lhs->s.size(); int sz = lhs->s.size();
char* buf = new char[sz * n + 1]; std::string buf(sz * n, '\0');
for (int i = 0; i < n; i++) { for (int i = 0; i < n; i++) {
memcpy(buf + (sz * i), lhs->s.c_str(), sz); memcpy(&buf[sz * i], lhs->s.c_str(), sz);
} }
buf[sz * n] = '\0'; return new BoxedString(std::move(buf));
return new BoxedString(buf);
} }
extern "C" Box* strLt(BoxedString* lhs, Box* rhs) { extern "C" Box* strLt(BoxedString* lhs, Box* rhs) {
......
...@@ -549,7 +549,7 @@ Box* sliceRepr(BoxedSlice* self) { ...@@ -549,7 +549,7 @@ Box* sliceRepr(BoxedSlice* self) {
BoxedString* stop = static_cast<BoxedString*>(repr(self->stop)); BoxedString* stop = static_cast<BoxedString*>(repr(self->stop));
BoxedString* step = static_cast<BoxedString*>(repr(self->step)); BoxedString* step = static_cast<BoxedString*>(repr(self->step));
std::string s = "slice(" + start->s + ", " + stop->s + ", " + step->s + ")"; std::string s = "slice(" + start->s + ", " + stop->s + ", " + step->s + ")";
return new BoxedString(s); return new BoxedString(std::move(s));
} }
Box* typeRepr(BoxedClass* self) { Box* typeRepr(BoxedClass* self) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment