From caa218398f831efbbb4863d26b7df39499532c7e Mon Sep 17 00:00:00 2001
From: Dimitrios Stoupis <dimitris.apple@gmail.com>
Date: Wed, 21 Nov 2018 10:20:41 +0000
Subject: [PATCH] Make subservice safer

---
 src/Services/MemMangService.cpp | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/src/Services/MemMangService.cpp b/src/Services/MemMangService.cpp
index 060cfbfe..d5c54539 100644
--- a/src/Services/MemMangService.cpp
+++ b/src/Services/MemMangService.cpp
@@ -1,5 +1,6 @@
 #include "Services/MemMangService.hpp"
 #include <iostream>
+#include <cerrno>
 
 // Define the constructors for the classes
 MemoryManagementService::MemoryManagementService() : rawDataMemorySubservice(this) {
@@ -67,6 +68,11 @@ void MemoryManagementService::RawDataMemoryManagement::dumpRawData(Message &requ
 		// Allocate more array space if needed
 		if (allocatedLength < readLength) {
 			readData = static_cast<uint8_t *>(realloc(readData, readLength));
+			if (!readData) {
+				// todo: Add error logging and reporting
+				free(readData);
+				return;
+			}
 		}
 
 		// Read memory data, an octet at a time
-- 
GitLab