[gjs/gnome-3-24] arg: Fix memory leaks
- From: Philip Chimento <pchimento src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gjs/gnome-3-24] arg: Fix memory leaks
- Date: Fri, 8 Sep 2017 03:42:07 +0000 (UTC)
commit bbb1739816586df2a7f36722f3e7a8490a35bbca
Author: Philip Chimento <philip endlessm com>
Date: Tue Aug 22 09:51:52 2017 -0700
arg: Fix memory leaks
Caught with Valgrind.
While touching this code, reindents it and fixes code style.
https://bugzilla.gnome.org/show_bug.cgi?id=786668
gi/arg.cpp | 45 +++++++++++++++++++++------------------------
1 files changed, 21 insertions(+), 24 deletions(-)
---
diff --git a/gi/arg.cpp b/gi/arg.cpp
index 6f211a5..c961ebe 100644
--- a/gi/arg.cpp
+++ b/gi/arg.cpp
@@ -1887,9 +1887,6 @@ gjs_value_to_g_argument(JSContext *context,
gpointer data;
gsize length;
GIArrayType array_type = g_type_info_get_array_type(type_info);
- GITypeInfo *param_info;
-
- param_info = g_type_info_get_param_type(type_info, 0);
/* First, let's handle the case where we're passed an instance
* of our own byteArray class.
@@ -1918,6 +1915,7 @@ gjs_value_to_g_argument(JSContext *context,
break;
}
+ GITypeInfo *param_info = g_type_info_get_param_type(type_info, 0);
if (array_type == GI_ARRAY_TYPE_C) {
arg->v_pointer = data;
} else if (array_type == GI_ARRAY_TYPE_ARRAY) {
@@ -2271,33 +2269,32 @@ gjs_array_from_carray_internal (JSContext *context,
ITERATE(double);
break;
case GI_TYPE_TAG_INTERFACE: {
- GIBaseInfo *interface_info;
- GIInfoType info_type;
-
- interface_info = g_type_info_get_interface (param_info);
- info_type = g_base_info_get_type (interface_info);
+ GIBaseInfo *interface_info = g_type_info_get_interface (param_info);
+ GIInfoType info_type = g_base_info_get_type (interface_info);
- if ((info_type == GI_INFO_TYPE_STRUCT ||
- info_type == GI_INFO_TYPE_UNION) &&
- !g_type_info_is_pointer (param_info)) {
- gsize struct_size;
+ if ((info_type == GI_INFO_TYPE_STRUCT ||
+ info_type == GI_INFO_TYPE_UNION) &&
+ !g_type_info_is_pointer(param_info)) {
+ size_t struct_size;
- if (info_type == GI_INFO_TYPE_UNION)
- struct_size = g_union_info_get_size ((GIUnionInfo*)interface_info);
- else
- struct_size = g_struct_info_get_size ((GIStructInfo*)interface_info);
+ if (info_type == GI_INFO_TYPE_UNION)
+ struct_size = g_union_info_get_size(interface_info);
+ else
+ struct_size = g_struct_info_get_size(interface_info);
- for (i = 0; i < length; i++) {
- arg.v_pointer = ((char*)array) + (struct_size * i);
+ for (i = 0; i < length; i++) {
+ arg.v_pointer = static_cast<char *>(array) + (struct_size * i);
- if (!gjs_value_from_g_argument(context, elems[i], param_info,
- &arg, true))
- return false;
- }
+ if (!gjs_value_from_g_argument(context, elems[i], param_info,
+ &arg, true))
+ return false;
+ }
- break;
- }
+ g_base_info_unref(interface_info);
+ break;
+ }
+ g_base_info_unref(interface_info);
}
/* fallthrough */
case GI_TYPE_TAG_GTYPE:
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]