[gjs] test: Fix use after free



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

    test: Fix use after free
    
    Noticed this while working on the unit test fixtures, 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 ac186d7..0e24ee4 100644
--- a/test/gjs-tests.cpp
+++ b/test/gjs-tests.cpp
@@ -127,7 +127,6 @@ gjstest_test_func_gjs_jsapi_util_error_throw(void)
     JSObject *global;
     JS::Value exc, value;
     char *s = NULL;
-    int strcmp_result;
 
     _gjs_unit_test_fixture_begin(&fixture);
     context = fixture.context;
@@ -150,11 +149,9 @@ gjstest_test_func_gjs_jsapi_util_error_throw(void)
     g_assert(value.isString());
 
     gjs_string_to_utf8(context, 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(context, s);
 
     /* keep this around before we clear it */
     JS::RootedValue previous(context, exc);


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