Преглед изворни кода

[1.6>master] [MERGE #3223 @xiaoyinl] Fix memory leak in Debugger::SetBaseline

Merge pull request #3223 from xiaoyinl:memleak_in_debugger

If `ChakraRTInterface::JsCreateString` fails, `IfJsrtErrorFailLogAndRetFalse` causes the function `Debugger::SetBaseline()` to return false, without deleting `script` and closing `file`.
Derek Morris пре 8 година
родитељ
комит
c1cdae013d
2 измењених фајлова са 12 додато и 1 уклоњено
  1. 1 1
      bin/ch/Debugger.cpp
  2. 11 0
      bin/ch/stdafx.h

+ 1 - 1
bin/ch/Debugger.cpp

@@ -327,7 +327,7 @@ bool Debugger::SetBaseline()
                 script[numChars] = '\0';
 
                 JsValueRef wideScriptRef;
-                IfJsrtErrorFailLogAndRetFalse(ChakraRTInterface::JsCreateString(
+                IfJsErrorFailLogAndHR(ChakraRTInterface::JsCreateString(
                   script, strlen(script), &wideScriptRef));
 
                 this->CallFunctionNoResult("SetBaseline", wideScriptRef);

+ 11 - 0
bin/ch/stdafx.h

@@ -105,6 +105,17 @@ do { \
     } \
 } while (0)
 
+#define IfJsErrorFailLogAndHR(expr) \
+do { \
+    JsErrorCode jsErrorCode = expr; \
+    if ((jsErrorCode) != JsNoError) { \
+        hr = E_FAIL; \
+        fwprintf(stderr, _u("ERROR: ") _u(#expr) _u(" failed. JsErrorCode=0x%x (%s)\n"), jsErrorCode, Helpers::JsErrorCodeToString(jsErrorCode)); \
+        fflush(stderr); \
+        goto Error; \
+    } \
+} while (0)
+
 #define IfJsErrorFailLogLabel(expr, label) \
 do { \
     JsErrorCode jsErrorCode = expr; \