[gjs] arg: Don't free data that we're only peeking at



commit 49eb746a0bcaf054fb7a5d879f4e2da28044f50d
Author: Jasper St. Pierre <jstpierre mecheye net>
Date:   Wed Jan 22 18:11:46 2014 -0500

    arg: Don't free data that we're only peeking at

 gi/arg.cpp |   10 ++++++----
 1 files changed, 6 insertions(+), 4 deletions(-)
---
diff --git a/gi/arg.cpp b/gi/arg.cpp
index b13c412..e704c4e 100644
--- a/gi/arg.cpp
+++ b/gi/arg.cpp
@@ -1671,6 +1671,7 @@ gjs_value_to_g_argument(JSContext      *context,
         GITypeTag element_type;
         GITypeInfo *param_info;
         gboolean bytearray_fastpath = FALSE;
+        gboolean free_data = TRUE;
 
         param_info = g_type_info_get_param_type(type_info, 0);
         element_type = g_type_info_get_tag(param_info);
@@ -1692,6 +1693,7 @@ gjs_value_to_g_argument(JSContext      *context,
                            (element_type == GI_TYPE_TAG_UINT8 || element_type == GI_TYPE_TAG_INT8)) {
                     gjs_byte_array_peek_data(context, bytearray_obj, (guint8**) &data, &length);
                     bytearray_fastpath = TRUE;
+                    free_data = FALSE;
                 } else {
                     /* Fall through, !handled */
                 }
@@ -1713,6 +1715,7 @@ gjs_value_to_g_argument(JSContext      *context,
 
         if (array_type == GI_ARRAY_TYPE_C) {
             arg->v_pointer = data;
+            free_data = FALSE;
         } else if (array_type == GI_ARRAY_TYPE_ARRAY) {
             GITypeInfo *param_info = g_type_info_get_param_type(type_info, 0);
             GArray *array = gjs_g_array_new_for_type(context, length, param_info);
@@ -1724,24 +1727,23 @@ gjs_value_to_g_argument(JSContext      *context,
                 arg->v_pointer = array;
             }
 
-            g_free(data);
             g_base_info_unref((GIBaseInfo*) param_info);
         } else if (array_type == GI_ARRAY_TYPE_BYTE_ARRAY) {
             GByteArray *byte_array = g_byte_array_sized_new(length);
 
             g_byte_array_append(byte_array, (const guint8 *) data, length);
             arg->v_pointer = byte_array;
-
-            g_free(data);
         } else if (array_type == GI_ARRAY_TYPE_PTR_ARRAY) {
             GPtrArray *array = g_ptr_array_sized_new(length);
 
             g_ptr_array_set_size(array, length);
             memcpy(array->pdata, data, sizeof(gpointer) * length);
             arg->v_pointer = array;
+        }
 
+        if (free_data)
             g_free(data);
-        }
+
         break;
     }
     default:


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