From d22591e24050b8200899a0de8854c39efff9effd Mon Sep 17 00:00:00 2001 From: Alexander Gavrilov Date: Fri, 14 Sep 2012 12:35:55 +0400 Subject: [PATCH] Fix a file descriptor leak and a crash in linux getMemRanges. --- library/Process-linux.cpp | 5 +++++ plugins/tweak.cpp | 4 ++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/library/Process-linux.cpp b/library/Process-linux.cpp index 4a66470f9..1fecbab78 100644 --- a/library/Process-linux.cpp +++ b/library/Process-linux.cpp @@ -127,6 +127,9 @@ void Process::getMemRanges( vector & ranges ) char permissions[5]; // r/-, w/-, x/-, p/s, 0 FILE *mapFile = ::fopen("/proc/self/maps", "r"); + if (!mapFile) + return; + size_t start, end, offset, device1, device2, node; while (fgets(buffer, 1024, mapFile)) @@ -148,6 +151,8 @@ void Process::getMemRanges( vector & ranges ) temp.valid = true; ranges.push_back(temp); } + + fclose(mapFile); } uint32_t Process::getBase() diff --git a/plugins/tweak.cpp b/plugins/tweak.cpp index de7695fb3..bebc346c5 100644 --- a/plugins/tweak.cpp +++ b/plugins/tweak.cpp @@ -89,10 +89,10 @@ DFhackCExport command_result plugin_init (color_ostream &out, std::vector \n" " Further improves temperature updates by ensuring that 1 degree of\n" " item temperature is crossed in no more than specified number of frames\n" - " when updating from the environment temperature.\n" + " when updating from the environment temperature. Use 0 to disable.\n" )); return CR_OK; }