summaryrefslogtreecommitdiff
path: root/src/pyinterp.cc
diff options
context:
space:
mode:
authorJohn Wiegley <johnw@newartisans.com>2009-11-07 20:00:34 -0500
committerJohn Wiegley <johnw@newartisans.com>2009-11-07 20:00:34 -0500
commit47c1089c61db32f85777847c88f4aed6ef2fc050 (patch)
treebc653cd0bec4c317b81bfd1d394b5b957f149c72 /src/pyinterp.cc
parent01255bdf6c621156c7a77e6ee9cfa46fb2c6f115 (diff)
downloadfork-ledger-47c1089c61db32f85777847c88f4aed6ef2fc050.tar.gz
fork-ledger-47c1089c61db32f85777847c88f4aed6ef2fc050.tar.bz2
fork-ledger-47c1089c61db32f85777847c88f4aed6ef2fc050.zip
Make sure to clean up memory after a Python exception
Diffstat (limited to 'src/pyinterp.cc')
-rw-r--r--src/pyinterp.cc14
1 files changed, 12 insertions, 2 deletions
diff --git a/src/pyinterp.cc b/src/pyinterp.cc
index b9e1a0e0..2df82563 100644
--- a/src/pyinterp.cc
+++ b/src/pyinterp.cc
@@ -255,12 +255,22 @@ value_t python_interpreter_t::python_command(call_scope_t& args)
std::strcpy(argv[i + 1], arg.c_str());
}
- int status = Py_Main(static_cast<int>(args.size()) + 1, argv);
+ int status;
+ try {
+ status = Py_Main(static_cast<int>(args.size()) + 1, argv);
+ }
+ catch (...) {
+ for (std::size_t i = 0; i < args.size() + 1; i++)
+ delete[] argv[i];
+ delete[] argv;
+ throw;
+ }
+
for (std::size_t i = 0; i < args.size() + 1; i++)
delete[] argv[i];
delete[] argv;
-
+
if (status != 0)
throw status;