diff --git a/CMakeLists.txt b/CMakeLists.txt
index f1f95f7e8da3d743fe47e1d2577adecf149e844a..17d302fda185a2728f7a826398f2447434361e98 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -139,11 +139,16 @@ IF(COMMAND SET_PROPERTY)
     "KWSYS_HEADER(%)=<${KWSYS_NAMESPACE}/%>"
     )
 ENDIF(COMMAND SET_PROPERTY)
+# add option to disable memory cleanup at exit of putenv memory
+IF(DEFINED KWSYS_DO_NOT_CLEAN_PUTENV)
+  SET(KWSYS_DO_NOT_CLEAN_PUTENV 1)
+ELSE(DEFINED KWSYS_DO_NOT_CLEAN_PUTENV)
+  SET(KWSYS_DO_NOT_CLEAN_PUTENV 0)
+ENDIF(DEFINED KWSYS_DO_NOT_CLEAN_PUTENV)
 
 # Select library components.
 IF(KWSYS_STANDALONE OR CMake_SOURCE_DIR)
   SET(KWSYS_ENABLE_C 1)
-
   # Enable all components.
   SET(KWSYS_USE_Base64 1)
   SET(KWSYS_USE_Directory 1)
diff --git a/Configure.hxx.in b/Configure.hxx.in
index 1536e727b0343a4794a4dadc699ed5be89f78dd0..4a3aebd18e5e5aeb5352e2f2acc84c31c5b539a2 100644
--- a/Configure.hxx.in
+++ b/Configure.hxx.in
@@ -18,7 +18,12 @@
 #include <@KWSYS_NAMESPACE@/Configure.h>
 
 /* Disable cleanup of putenv memory for issues with GCOV */
-#cmakedefine KWSYS_DO_NOT_CLEAN_PUTENV
+#if @KWSYS_DO_NOT_CLEAN_PUTENV@
+#define KWSYS_DO_NOT_CLEAN_PUTENV 
+#else
+#undef KWSYS_DO_NOT_CLEAN_PUTENV
+#else
+
 
 /* Whether ANSI C++ stream headers are to be used.  */
 #define @KWSYS_NAMESPACE@_IOS_USE_ANSI @KWSYS_IOS_USE_ANSI@