[gjs/wip/ptomato/mozjs31prep: 3/3] test: Fix use after free



commit 409b5df34cdcd08d5d897998d51e11b603ff8c37
Author: Philip Chimento <philip chimento gmail com>
Date:   Sun Oct 16 23:05:02 2016 -0700

    test: Fix use after free
    
    Noticed this while writing the previous commit, so cleaned it up.

 test/gjs-tests.cpp |    9 +++------
 1 files changed, 3 insertions(+), 6 deletions(-)
---
diff --git a/test/gjs-tests.cpp b/test/gjs-tests.cpp
index 9644528..33f1454 100644
--- a/test/gjs-tests.cpp
+++ b/test/gjs-tests.cpp
@@ -123,7 +123,6 @@ gjstest_test_func_gjs_jsapi_util_error_throw(GjsUnitTestFixture *fx,
 {
     JS::Value exc, value;
     char *s = NULL;
-    int strcmp_result;
 
     /* Test that we can throw */
 
@@ -142,11 +141,9 @@ gjstest_test_func_gjs_jsapi_util_error_throw(GjsUnitTestFixture *fx,
     g_assert(value.isString());
 
     gjs_string_to_utf8(fx->cx, value, &s);
-    g_assert(s != NULL);
-    strcmp_result = strcmp(s, "This is an exception 42");
-    free(s);
-    if (strcmp_result != 0)
-        g_error("Exception has wrong message '%s'", s);
+    g_assert_nonnull(s);
+    g_assert_cmpstr(s, ==, "This is an exception 42");
+    JS_free(fx->cx, s);
 
     /* keep this around before we clear it */
     JS::RootedValue previous(fx->cx, exc);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]