From 42afbc23130c0eda99833e915a9b182a92bd91c6 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Eckl=2C=20M=C3=A1t=C3=A9?= <ecklm@sch.bme.hu>
Date: Sat, 9 May 2015 22:06:29 +0200
Subject: [PATCH] =?UTF-8?q?A=20mem=C3=B3riahiba=20jav=C3=ADtva=20(heap.cpp?=
 =?UTF-8?q?=2072.=20sor).=20M=C3=A9g=20az=C3=A9rt=20nem=20=C3=A1rt=20meg?=
 =?UTF-8?q?=C3=A9rteni=20pontosan=20a=20dolgot.=20A=20proc=5Ftest=20destru?=
 =?UTF-8?q?ktor=C3=A1t=20az=C3=A9rt=20kellett=20t=C3=B6r=C3=B6lni,=20mert?=
 =?UTF-8?q?=20=C3=ADgy=20biztons=C3=A1gosabb,=20csak=20epliciten=20kell=20?=
 =?UTF-8?q?h=C3=ADvni=20a=20process-t=C5=91l=20sz=C3=A1rmazott=20tagf?=
 =?UTF-8?q?=C3=BCggv=C3=A9nyt.?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 NHF/include/proc_test.h    | 2 +-
 NHF/main.cpp               | 9 +++++----
 NHF/src/heap.cpp           | 2 +-
 NHF/src/test_container.cpp | 2 ++
 NHF/tests/test_2           | 2 +-
 NHF/tests/test_5           | 7 +++++++
 6 files changed, 17 insertions(+), 7 deletions(-)
 create mode 100644 NHF/tests/test_5

diff --git a/NHF/include/proc_test.h b/NHF/include/proc_test.h
index 1d5fbc3..ef22d5a 100644
--- a/NHF/include/proc_test.h
+++ b/NHF/include/proc_test.h
@@ -28,7 +28,7 @@ class proc_test : public process
 		void operator=(const proc_test&);
 		std::string get_name() { return name; }
 		proc_test* get_next() { return next; }
-		~proc_test(){this->kill();}
+//		~proc_test(){this->kill();}
 	private:
 		std::string name;/**< A process neve */
 		proc_test* next;/**< A következő listaelemre mutató pointer */
diff --git a/NHF/main.cpp b/NHF/main.cpp
index 03cc324..10b6478 100644
--- a/NHF/main.cpp
+++ b/NHF/main.cpp
@@ -8,7 +8,7 @@
 using namespace std;
 
 #ifdef DEBUG
-	ifstream fin("/home/mate/Dropbox/Egyetem/Tárgyak/2015 tavasz/Programozás alapjai 2/NHF/NHF/tests/test_2");
+	ifstream fin("/home/mate/Dropbox/Egyetem/Tárgyak/2015 tavasz/Programozás alapjai 2/NHF/NHF/tests/test_1");
 	#define cin fin
 #endif // DEBUG
 
@@ -45,12 +45,14 @@ int main()
 				case '+':
 					try
 					{
-						cout<<"Adding process of name '"<<request.name<<"' and size of blocks "<<request.block_size<<".\n";
-						procs.add(new proc_test(request.name,process(mem),request.block_size)); break;
+						cout<<"Adding process of name '"<<request.name<<"' and of size "<<request.block_size<<".\n";
+						procs.add(new proc_test(request.name,process(mem),request.block_size));
+						break;
 					}
 					catch(domain_error& err)
 					{
                         cerr<<err.what()<<" "<<"A(z) '"<<request.name<<"'processz beszúrása meghiúsult."<<endl;
+                        break;
 					}
 				case '-':
 					cout<<"Killing process of name '"<<request.name<<"'.\n";
@@ -68,7 +70,6 @@ int main()
 	{
 		cerr<<err<<endl;
 	}
-
 	#ifdef DEBUG
 		fin.close();
 	#endif // DEBUG
diff --git a/NHF/src/heap.cpp b/NHF/src/heap.cpp
index 9879b1d..0bfd24d 100644
--- a/NHF/src/heap.cpp
+++ b/NHF/src/heap.cpp
@@ -68,7 +68,7 @@ void heap::free(const memnum pid)
 		throw (invalid_pid("A hivatkozott blokk már üres."));
 	else if(blocks[pid].filled && blocks[pid].block_size==0)
 		throw (invalid_pid("Ezen a címen nem kezdődik memóriablokk"));
-	memnum next_block_idx=pid+blocks[pid].block_size;
+	memnum next_block_idx=pid+blocks[pid].block_size-1;
 	for(memnum i=pid+1; i<next_block_idx; i++)
 		blocks[i].reset();
 	/*
diff --git a/NHF/src/test_container.cpp b/NHF/src/test_container.cpp
index bae0a92..265d9af 100644
--- a/NHF/src/test_container.cpp
+++ b/NHF/src/test_container.cpp
@@ -8,6 +8,7 @@ void test_container::kill(const std::string& name)
 	{
 		k=list_head;
 		list_head=list_head->next;
+		k->kill();
 		delete k;
 		return;
 	}
@@ -17,6 +18,7 @@ void test_container::kill(const std::string& name)
 	if(k==NULL)
 		throw (std::invalid_argument("Érvénytelen processnév"));
 	i->next=k->next;
+	k->kill();
 	delete k;
 }
 
diff --git a/NHF/tests/test_2 b/NHF/tests/test_2
index 28ac251..ebd8894 100644
--- a/NHF/tests/test_2
+++ b/NHF/tests/test_2
@@ -5,5 +5,5 @@
 #
 + windows 5001
 #
-+linux 533
++ linux 533
 #
diff --git a/NHF/tests/test_5 b/NHF/tests/test_5
new file mode 100644
index 0000000..81c7d2c
--- /dev/null
+++ b/NHF/tests/test_5
@@ -0,0 +1,7 @@
+100
++ pidgin 10
++ awesome 5
++ i3 1
+#
+- awesome
+#
-- 
GitLab