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



commit 8b159cb40af02d46a4a9b5b71d59b1a4756d9cea
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.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=742249

 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 9f0eb3c..11c903e 100644
--- a/test/gjs-tests.cpp
+++ b/test/gjs-tests.cpp
@@ -125,7 +125,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 */
 
@@ -144,11 +143,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]