fix: memory leak
This commit is contained in:
@ -1,6 +1,6 @@
|
|||||||
set(PROJECT_NAME ${CMAKE_PROJECT_NAME})
|
set(PROJECT_NAME ${CMAKE_PROJECT_NAME})
|
||||||
set(CMAKE_CXX_STANDARD 17)
|
set(CMAKE_CXX_STANDARD 17)
|
||||||
set(CMAKE_CXX_FLAGS " -g")
|
set(CMAKE_CXX_FLAGS "-fsanitize=address -g")
|
||||||
set(ENV{MAKEFLAGS} "-j16")
|
set(ENV{MAKEFLAGS} "-j16")
|
||||||
include_directories(${PROJECT_SOURCE_DIR}/include)
|
include_directories(${PROJECT_SOURCE_DIR}/include)
|
||||||
link_directories(${PROJECT_SOURCE_DIR}/src)
|
link_directories(${PROJECT_SOURCE_DIR}/src)
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
set(PROJECT_NAME ${CMAKE_PROJECT_NAME})
|
set(PROJECT_NAME ${CMAKE_PROJECT_NAME})
|
||||||
set(CMAKE_CXX_STANDARD 17)
|
set(CMAKE_CXX_STANDARD 17)
|
||||||
set(CMAKE_CXX_FLAGS " -g")
|
set(CMAKE_CXX_FLAGS "-fsanitize=address -g")
|
||||||
include_directories(${PROJECT_SOURCE_DIR}/include)
|
include_directories(${PROJECT_SOURCE_DIR}/include)
|
||||||
add_library(int2048 STATIC int2048.cpp)
|
add_library(int2048 STATIC int2048.cpp)
|
@ -221,6 +221,7 @@ int2048 &int2048::add(const int2048 &B) {
|
|||||||
this->flag = 1;
|
this->flag = 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (pB != &B) delete pB;
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -272,6 +273,7 @@ int2048 &int2048::minus(const int2048 &B) {
|
|||||||
if (this == &B) pB = new int2048(B);
|
if (this == &B) pB = new int2048(B);
|
||||||
UnsignedAdd(*this, pB);
|
UnsignedAdd(*this, pB);
|
||||||
}
|
}
|
||||||
|
if (pB != &B) delete pB;
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -442,10 +444,12 @@ int2048 &int2048::Multiply(const int2048 &B) {
|
|||||||
if ((this->num_length == 1 && this->val[0] == 0) ||
|
if ((this->num_length == 1 && this->val[0] == 0) ||
|
||||||
(pB->num_length == 1 && pB->val[0] == 0)) {
|
(pB->num_length == 1 && pB->val[0] == 0)) {
|
||||||
*this = std::move(int2048(0));
|
*this = std::move(int2048(0));
|
||||||
|
if (pB != &B) delete pB;
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
this->flag = this->flag * pB->flag;
|
this->flag = this->flag * pB->flag;
|
||||||
UnsignedMultiply(*this, pB);
|
UnsignedMultiply(*this, pB);
|
||||||
|
if (pB != &B) delete pB;
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -495,6 +499,7 @@ void int2048::RightMoveBy(int L) {
|
|||||||
|
|
||||||
inline void UnsignedDivide(int2048 &A, const int2048 *pB) {
|
inline void UnsignedDivide(int2048 &A, const int2048 *pB) {
|
||||||
int L1 = A.num_length, L2 = pB->num_length;
|
int L1 = A.num_length, L2 = pB->num_length;
|
||||||
|
if (&A == pB) throw "UnsignedDivide: A and B are the same object";
|
||||||
if (2 * L1 - L2 - 1 < 0) {
|
if (2 * L1 - L2 - 1 < 0) {
|
||||||
A = std::move(int2048(0));
|
A = std::move(int2048(0));
|
||||||
return;
|
return;
|
||||||
@ -597,15 +602,15 @@ int2048 operator/(int2048 A, const int2048 &B) {
|
|||||||
|
|
||||||
int2048 &int2048::operator%=(const int2048 &B) {
|
int2048 &int2048::operator%=(const int2048 &B) {
|
||||||
// 实现复合取模逻辑
|
// 实现复合取模逻辑
|
||||||
int2048 C=(*this)/B;
|
int2048 C = (*this) / B;
|
||||||
*this=*this-C*B;
|
*this = *this - C * B;
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
int2048 operator%(int2048 A, const int2048 &B) {
|
int2048 operator%(int2048 A, const int2048 &B) {
|
||||||
// 实现取模逻辑
|
// 实现取模逻辑
|
||||||
int2048 C=A/B;
|
int2048 C = A / B;
|
||||||
return A-C*B;
|
return A - C * B;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::istream &operator>>(std::istream &stream, int2048 &V) {
|
std::istream &operator>>(std::istream &stream, int2048 &V) {
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
{
|
{
|
||||||
"StatusInterpreter":{"0":"OK","1":"Wrong Answer","139":"Segmentation fault"},
|
"StatusInterpreter":{"0":"OK","1":"Wrong Answer","139":"Segmentation fault","137":"(Killed) maybe Time Limit Error"},
|
||||||
"Cases":
|
"Cases":
|
||||||
[
|
[
|
||||||
{"command":"timeout -s 9 10s /home/happyzym/CSWorkSpace/Proc/BigHomework/BH-int2048-2023/build/data/C1T1 >/tmp/C1T1.out && diff -b -B -u /tmp/C1T1.out /home/happyzym/CSWorkSpace/Proc/BigHomework/BH-int2048-2023/data/Integer1/1.out >/tmp/diffC1T1","uid":"#1","tid":"/1/1"},
|
{"command":"timeout -s 9 10s /home/happyzym/CSWorkSpace/Proc/BigHomework/BH-int2048-2023/build/data/C1T1 >/tmp/C1T1.out && diff -b -B -u /tmp/C1T1.out /home/happyzym/CSWorkSpace/Proc/BigHomework/BH-int2048-2023/data/Integer1/1.out >/tmp/diffC1T1","uid":"#1","tid":"/1/1"},
|
||||||
@ -24,7 +24,7 @@
|
|||||||
{"command":"timeout -s 9 10s /home/happyzym/CSWorkSpace/Proc/BigHomework/BH-int2048-2023/build/data/C2T15 >/tmp/C2T15.out && diff -b -B -u /tmp/C2T15.out /home/happyzym/CSWorkSpace/Proc/BigHomework/BH-int2048-2023/data/Integer2/15.out >/tmp/diffC2T15","uid":"#25","tid":"/2/15"},
|
{"command":"timeout -s 9 10s /home/happyzym/CSWorkSpace/Proc/BigHomework/BH-int2048-2023/build/data/C2T15 >/tmp/C2T15.out && diff -b -B -u /tmp/C2T15.out /home/happyzym/CSWorkSpace/Proc/BigHomework/BH-int2048-2023/data/Integer2/15.out >/tmp/diffC2T15","uid":"#25","tid":"/2/15"},
|
||||||
{"command":"timeout -s 9 10s /home/happyzym/CSWorkSpace/Proc/BigHomework/BH-int2048-2023/build/data/C2T16 >/tmp/C2T16.out && diff -b -B -u /tmp/C2T16.out /home/happyzym/CSWorkSpace/Proc/BigHomework/BH-int2048-2023/data/Integer2/16.out >/tmp/diffC2T16","uid":"#26","tid":"/2/16"},
|
{"command":"timeout -s 9 10s /home/happyzym/CSWorkSpace/Proc/BigHomework/BH-int2048-2023/build/data/C2T16 >/tmp/C2T16.out && diff -b -B -u /tmp/C2T16.out /home/happyzym/CSWorkSpace/Proc/BigHomework/BH-int2048-2023/data/Integer2/16.out >/tmp/diffC2T16","uid":"#26","tid":"/2/16"},
|
||||||
{"command":"timeout -s 9 10s /home/happyzym/CSWorkSpace/Proc/BigHomework/BH-int2048-2023/build/data/C2T17 >/tmp/C2T17.out && diff -b -B -u /tmp/C2T17.out /home/happyzym/CSWorkSpace/Proc/BigHomework/BH-int2048-2023/data/Integer2/17.out >/tmp/diffC2T17","uid":"#27","tid":"/2/17"},
|
{"command":"timeout -s 9 10s /home/happyzym/CSWorkSpace/Proc/BigHomework/BH-int2048-2023/build/data/C2T17 >/tmp/C2T17.out && diff -b -B -u /tmp/C2T17.out /home/happyzym/CSWorkSpace/Proc/BigHomework/BH-int2048-2023/data/Integer2/17.out >/tmp/diffC2T17","uid":"#27","tid":"/2/17"},
|
||||||
{"command":"timeout -s 9 10s /home/happyzym/CSWorkSpace/Proc/BigHomework/BH-int2048-2023/build/data/C2T18 >/tmp/C2T18.out && diff -b -B -u /tmp/C2T18.out /home/happyzym/CSWorkSpace/Proc/BigHomework/BH-int2048-2023/data/Integer2/18.out >/tmp/diffC2T18","uid":"#28","tid":"/2/18"},
|
{"command":"timeout -s 9 60s /home/happyzym/CSWorkSpace/Proc/BigHomework/BH-int2048-2023/build/data/C2T18 >/tmp/C2T18.out && diff -b -B -u /tmp/C2T18.out /home/happyzym/CSWorkSpace/Proc/BigHomework/BH-int2048-2023/data/Integer2/18.out >/tmp/diffC2T18","uid":"#28","tid":"/2/18"},
|
||||||
{"command":"/home/happyzym/CSWorkSpace/Proc/BigHomework/BH-int2048-2023/tester/cases/1.py","uid":"#29","tid":"/3/1"},
|
{"command":"/home/happyzym/CSWorkSpace/Proc/BigHomework/BH-int2048-2023/tester/cases/1.py","uid":"#29","tid":"/3/1"},
|
||||||
{"command":"/home/happyzym/CSWorkSpace/Proc/BigHomework/BH-int2048-2023/tester/cases/2.py","uid":"#30","tid":"/3/2"},
|
{"command":"/home/happyzym/CSWorkSpace/Proc/BigHomework/BH-int2048-2023/tester/cases/2.py","uid":"#30","tid":"/3/2"},
|
||||||
{"command":"/home/happyzym/CSWorkSpace/Proc/BigHomework/BH-int2048-2023/tester/cases/3.py","uid":"#31","tid":"/3/3"}
|
{"command":"/home/happyzym/CSWorkSpace/Proc/BigHomework/BH-int2048-2023/tester/cases/3.py","uid":"#31","tid":"/3/3"}
|
||||||
|
Reference in New Issue
Block a user