diff --git a/lab_2/12/Makefile b/lab_2/12/Makefile new file mode 100644 index 0000000..0ef13b8 --- /dev/null +++ b/lab_2/12/Makefile @@ -0,0 +1,18 @@ +binary = memleak +folder = memleak +objects = $(patsubst %.cpp,%.o,$(wildcard *.cpp)) + +run: $(binary) + ./$(binary) 7 100000000 + +$(binary): $(objects) + g++ -o $@ $^ + +clean: + rm -f *.o + +clear: clean + rm -f *.zip $(binary) + +zip: clean + zip $(folder) Makefile *.cpp *.h diff --git a/lab_2/12/chain-random-walk.o b/lab_2/12/chain-random-walk.o new file mode 100644 index 0000000..5c67061 Binary files /dev/null and b/lab_2/12/chain-random-walk.o differ diff --git a/lab_2/12/memleak.cpp b/lab_2/12/memleak.cpp index 89b57b9..5833225 100644 --- a/lab_2/12/memleak.cpp +++ b/lab_2/12/memleak.cpp @@ -45,7 +45,11 @@ int main(int argc, char** argv) /* here we are calling the random walk step; * this returns a new configuration (float array) on the heap */ + + // Simple fix to memleak: + float* old_configuration = present_configuration; present_configuration = crw::step(size, present_configuration); + delete old_configuration; float present_elongation = crw::elongation(size, present_configuration); if(present_elongation > extreme_elongation)