Hi, Noone to give me a support on this ? It is the bad place to ask this kind of question ? Do I have to find another mailing list ? This mailing list seems to be deserted. I also try to use last version of dbus, glib-dbus, glib to see if I am able to fix my leak but no improvement.
I also recode from scratch a client and a server which are very simple. I am able to run it on a fedora 16 without leak. If I use it on my embedded device... leak is always there. Source can be found here : http://arthurlambert.fr/robotique/test_dbus.tar.bz2 It is quite sad, I can identify which lines are causing a leak without be able to find a fix ! Regards, Arthur 2014-03-06 14:11 GMT+01:00 Arthur Lambert <[email protected]>: > Hi Simon, > > First, when I put all the free that I have to put, the code get a > segfault. In fact It seems that I just have to use g_ptr_array_free on > the upper structure that is the ptr_array to free all memory. If I put > more free, I get plenty of invalid free though valgrind test and > segfault. > > Second, How can you explain that I am not able to see any leak with ps > aux command if I put a loop in my main (or only on some specific > target) ? Do they have a way to garbarge memory in glib ? > > Last point is I am currently using this code in dbus. I cannot use > free because all this structure is send though dbus. I get a pointer > by argument on a callback. I use the pointer to set the answer. So I > suppose that dbus must free all the structure by itself riight ? > > Regards, > Arthur. > > 2014-03-06 12:58 GMT+01:00 Simon Kågedal Reimer <[email protected]>: >> Hi Arthur, >> >> In C code, memory is managed manually. Every time you dynamically allocate >> memory, such as with GLib's various _new() functions, you need to return >> that chunk of memory to the system when you are done using it. I see no such >> calls in your code. For example, a GPtrArray created with g_ptr_array_new() >> should have a matching call to g_ptr_array_unref() or g_ptr_array_free(). A >> call to g_new0 should have a matching g_free, I don't know why you have >> commented that out. And so on. >> >> Best regards! Simon >> >> >> On Tue, Mar 4, 2014 at 3:44 PM, Arthur Lambert <[email protected]> >> wrote: >>> >>> >>> Hi All, >>> >>> I am using glib with GValue, GPtrArray to communicate with dbus. I >>> have a big memory leak in my code. I am running an embedded target >>> with glib 2.32.4. I am currently trying to code some little binary to >>> detect the leak. I am not the author of the code so it is quite hard >>> for me to debug it. >>> >>> So I have currently for example a little main which does not leak at >>> all on a desktop linux version (Fedora 17) which use the same glib >>> version( perhaps not exactly the same verson but major, minor and >>> macro number version seems to be the same. But when I run this piece >>> of code on my embedded linux, I have a leak of 4 Bytes per loop >>> iteration. >>> >>> Code is : >>> #define SIZE_INNER_ARRAY 5 >>> ... >>> >>> static void >>> data_constructor_array_struct_string_array_struct_string_variant(GPtrArray >>> *data, const gchar *client_objname) >>> { >>> guint member_count; >>> GValueArray *outer_struct = g_value_array_new(1); >>> GPtrArray *inner_array = g_ptr_array_new (); >>> >>> printf ("client objname : %s\n", client_objname); >>> >>> g_value_array_append(outer_struct, NULL); >>> g_value_init(g_value_array_get_nth(outer_struct, 0), G_TYPE_STRING); >>> g_value_set_string(g_value_array_get_nth(outer_struct, 0), >>> client_objname); >>> >>> for(member_count=0;member_count < SIZE_INNER_ARRAY ;member_count++) >>> { >>> GValueArray *inner_struct = g_value_array_new(2); >>> g_value_array_append(inner_struct, NULL); >>> g_value_init(g_value_array_get_nth(inner_struct, 0), G_TYPE_STRING); >>> >>> char str[32]; >>> sprintf (str, "TUTU%d", member_count); >>> g_value_set_string(g_value_array_get_nth(inner_struct, 0), str); >>> >>> GValue *ptr = g_new0 (GValue, 1); >>> g_value_init (ptr, G_TYPE_UINT); >>> g_value_set_uint (ptr, member_count); >>> >>> g_value_array_append(inner_struct, NULL); >>> g_value_init(g_value_array_get_nth(inner_struct, 1), G_TYPE_VALUE); >>> g_value_set_static_boxed(g_value_array_get_nth(inner_struct, 1), ptr); >>> //g_free(ptr); // can remove it, but use set_static instead of set >>> >>> g_ptr_array_add(inner_array, inner_struct); >>> } >>> >>> g_value_array_append(outer_struct, NULL); >>> g_value_init(g_value_array_get_nth(outer_struct, 1), >>> dbus_g_type_get_collection("GPtrArray",dbus_g_type_get_struct >>> ("GValueArray", G_TYPE_STRING, G_TYPE_VALUE, G_TYPE_INVALID))); >>> g_value_set_boxed (g_value_array_get_nth(outer_struct, 1), inner_array); >>> >>> g_ptr_array_add(data, outer_struct); >>> } >>> >>> int main (void) >>> { >>> GPtrArray *ptr_array = NULL; >>> g_type_init (); >>> //while (1) >>> { >>> ptr_array = g_ptr_array_new (); >>> data_constructor_array_struct_string_array_struct_string_variant >>> (ptr_array, "mon objet"); >>> //sleep (3); >>> } >>> return 0; >>> } >>> >>> To summarize the code. I have an outer_struct which is a GValueArray. >>> First element is a gvalue with a string. Second element is inner_array >>> which is a GPtrArray. Each element of inner_array is a innner_struct >>> which is a GValueArray compose of two elements. As you can see in this >>> example I am adding 5 inner_struct in the inner_array. >>> >>> Do I am doing something wrong in this code ? Do I have a memory leak >>> in my glib version ? >>> I hope that it is the good place to ask my request. >>> >>> Thanks & Regards >>> Arthur. >>> _______________________________________________ >>> gnome-devel-list mailing list >>> [email protected] >>> https://mail.gnome.org/mailman/listinfo/gnome-devel-list >> >> > > > > -- > - Arthur LAMBERT -- - Arthur LAMBERT _______________________________________________ gnome-devel-list mailing list [email protected] https://mail.gnome.org/mailman/listinfo/gnome-devel-list
