From 4eca161ae0f815eef0af35af9af7ce365ae0dd04 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Mart=C3=ADn?= Date: Mon, 18 Jun 2012 18:12:17 +0200 Subject: [PATCH] Bug #1310: Free memory in certain error situations, when a VM is created --- src/vm/VirtualMachine.cc | 32 +++++++++++++++++++++++++++----- 1 file changed, 27 insertions(+), 5 deletions(-) diff --git a/src/vm/VirtualMachine.cc b/src/vm/VirtualMachine.cc index c06f552293..990f8f28db 100644 --- a/src/vm/VirtualMachine.cc +++ b/src/vm/VirtualMachine.cc @@ -379,7 +379,7 @@ int VirtualMachine::parse_context(string& error_str) else if ( num > 1 ) { error_str = "Only one CONTEXT attribute can be defined."; - return -1; + goto error_cleanup; } context = dynamic_cast(array_context[0]); @@ -387,7 +387,7 @@ int VirtualMachine::parse_context(string& error_str) if ( context == 0 ) { error_str = "Wrong format for CONTEXT attribute."; - return -1; + goto error_cleanup; } str = context->marshall(" @^_^@ "); @@ -395,7 +395,7 @@ int VirtualMachine::parse_context(string& error_str) if (str == 0) { NebulaLog::log("ONE",Log::ERROR, "Cannot marshall CONTEXT"); - return -1; + goto error_cleanup; } rc = parse_template_attribute(*str,parsed); @@ -421,6 +421,17 @@ int VirtualMachine::parse_context(string& error_str) } return rc; + +error_cleanup: + for (int i = 0; i < num ; i++) + { + if (array_context[i] != 0) + { + delete array_context[i]; + } + } + + return -1; } /* -------------------------------------------------------------------------- */ @@ -489,7 +500,7 @@ int VirtualMachine::parse_requirements(string& error_str) else if ( num > 1 ) { error_str = "Only one REQUIREMENTS attribute can be defined."; - return -1; + goto error_cleanup; } reqs = dynamic_cast(array_reqs[0]); @@ -497,7 +508,7 @@ int VirtualMachine::parse_requirements(string& error_str) if ( reqs == 0 ) { error_str = "Wrong format for REQUIREMENTS attribute."; - return -1; + goto error_cleanup; } rc = parse_template_attribute(reqs->value(),parsed); @@ -521,6 +532,17 @@ int VirtualMachine::parse_requirements(string& error_str) } return rc; + +error_cleanup: + for (int i = 0; i < num ; i++) + { + if (array_reqs[i] != 0) + { + delete array_reqs[i]; + } + } + + return -1; } /* ------------------------------------------------------------------------ */