[gjs: 5/9] importer: use gjs_string_from_utf8 to convert strings
- From: Philip Chimento <pchimento src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gjs: 5/9] importer: use gjs_string_from_utf8 to convert strings
- Date: Tue, 6 Nov 2018 04:06:17 +0000 (UTC)
commit 08bd2d3ea2997f5159d1c3d690cbef5933c200db
Author: Marco Trevisan (TreviƱo) <mail 3v1n0 net>
Date: Sat Oct 13 19:14:01 2018 -0500
importer: use gjs_string_from_utf8 to convert strings
Using simply JS_NewStringCopyZ was leaking as per asan checks
gjs/importer.cpp | 13 +++++++++----
1 file changed, 9 insertions(+), 4 deletions(-)
---
diff --git a/gjs/importer.cpp b/gjs/importer.cpp
index 58d9ec6e..09d068ad 100644
--- a/gjs/importer.cpp
+++ b/gjs/importer.cpp
@@ -120,7 +120,9 @@ define_meta_properties(JSContext *context,
module_name ? module_name : "<root>", parent_is_module);
if (full_path != NULL) {
- JS::RootedString file(context, JS_NewStringCopyZ(context, full_path));
+ JS::RootedValue file(context);
+ if (!gjs_string_from_utf8(context, full_path, &file))
+ return false;
if (!JS_DefineProperty(context, module_obj, "__file__", file, attrs))
return false;
}
@@ -132,7 +134,8 @@ define_meta_properties(JSContext *context,
JS::RootedValue module_path(context, JS::NullValue());
JS::RootedValue to_string_tag(context);
if (parent_is_module) {
- module_name_val.setString(JS_NewStringCopyZ(context, module_name));
+ if (!gjs_string_from_utf8(context, module_name, &module_name_val))
+ return false;
parent_module_val.setObject(*parent);
JS::RootedValue parent_module_path(context);
@@ -150,11 +153,13 @@ define_meta_properties(JSContext *context,
return false;
module_path_buf = g_strdup_printf("%s.%s", parent_path.get(), module_name);
}
- module_path.setString(JS_NewStringCopyZ(context, module_path_buf));
+ if (!gjs_string_from_utf8(context, module_path_buf, &module_path))
+ return false;
GjsAutoChar to_string_tag_buf = g_strdup_printf("GjsModule %s",
module_path_buf.get());
- to_string_tag.setString(JS_NewStringCopyZ(context, to_string_tag_buf));
+ if (!gjs_string_from_utf8(context, to_string_tag_buf, &to_string_tag))
+ return false;
} else {
to_string_tag.setString(JS_AtomizeString(context, "GjsModule"));
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]