Memory allocation issue in GtkAda 3.8 ?

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Memory allocation issue in GtkAda 3.8 ?

Rob Groen

Hello all,

As a follow up on the discussion last March wrt memory allocation problems in GtkAda 3.x, I tried one of my failing programs with Gtkada 3.8. Unfortunately with the same result.

I tried this on Windows 7, both on a 64- and on a 32-bit environment, using the GNAT GPL 2014 compiler. In order to track the problem I stripped my original application to a simple window with a treeview / liststore, consisting of one column of type Gtype_String. The liststore gets loaded with a nr of strings, then a search in the store is performed. In the search a Get_String is done on an element of the store.

When an allocator is used prior searching ( sp := new String'("") ), the program crashes after a few searches. When either the allocator or the Get_String is omitted the program runs to completion.
(The nr of strings to put into the store and the nr of searches vary with the code, logging statements, etc etc. The current nrs are those that crashes the program in my environments, Win7 32- and 64-bit.)

For those who want to research / replay this issue a zip file with the code and a .gpr file can be found at: http://robgr.home.xs4all.nl/gtkada3x_bug.zip. The "offending" code is in the file gtkada3x_bug_support.adb.
Unfortunately I do not have the knowledge to research this problem.

If there are problems downloading, let me know, then I will send the zip file.

Best regards

Rob Groen

(PS I hope that it is not something in my code... that would be so embarrassing. I have looked it over and over umpteen times.)

 

 

 

_______________________________________________
gtkada mailing list
[hidden email]
http://lists.adacore.com/mailman/listinfo/gtkada
Reply | Threaded
Open this post in threaded view
|

Re: Memory allocation issue in GtkAda 3.8 ?

Dmitry A. Kazakov
On Sun, 29 Jun 2014 18:11:33 +0200, you wrote:

> As a follow up on the discussion last March wrt memory allocation
> problems in GtkAda 3.x, I tried one of my failing programs with Gtkada
> 3.8. Unfortunately with the same result.
>
> I tried this on Windows 7, both on a 64- and on a 32-bit environment,
> using the GNAT GPL 2014 compiler. In order to track the problem I
> stripped my original application to a simple window with a treeview /
> liststore, consisting of one column of type Gtype_String. The liststore
> gets loaded with a nr of strings, then a search in the store is
> performed. In the search a Get_String is done on an element of the
> store.
>
> When an allocator is used prior searching ( sp := new String'("") ), the
> program crashes after a few searches. When either the allocator or the
> Get_String is omitted the program runs to completion.
> (The nr of strings to put into the store and the nr of searches vary
> with the code, logging statements, etc etc. The current nrs are those
> that crashes the program in my environments, Win7 32- and 64-bit.)
>
> For those who want to research / replay this issue a zip file with the
> code and a .gpr file can be found at:
> http://robgr.home.xs4all.nl/gtkada3x_bug.zip. The "offending" code is in
> the file gtkada3x_bug_support.adb.
> Unfortunately I do not have the knowledge to research this problem.

If I correctly remember, I might be wrong, the problem is with the Set
procedure of Gtk_List_Store with a string argument.

A workaround is to use Set_Value instead. You do Init of a GValue with
GType_String. Set the string into it. Then Set_Value to update the list
store and, finally, Unset the GValue object.

--
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de
_______________________________________________
gtkada mailing list
[hidden email]
http://lists.adacore.com/mailman/listinfo/gtkada
Reply | Threaded
Open this post in threaded view
|

Re: Memory allocation issue in GtkAda 3.8 ?

Emmanuel Briot
>> For those who want to research / replay this issue a zip file with the
>> code and a .gpr file can be found at:
>> http://robgr.home.xs4all.nl/gtkada3x_bug.zip. The "offending" code is in
>> the file gtkada3x_bug_support.adb.
>> Unfortunately I do not have the knowledge to research this problem.

I tried running on my machine (OSX), including with valgrind, but could reproduce
neither a crash nor an error reported by valgrind (but valgrind is pretty bad on OSX,
so this might not be exactly accurate).

That said, I would agree with Dmitry that the implementation of Gtk.List_Store.Set
might be incorrect, and it would be better to convert to a GValue first.

Can you try applying the following patch ?


_______________________________________________
gtkada mailing list
[hidden email]
http://lists.adacore.com/mailman/listinfo/gtkada

patch.txt (4K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Memory allocation issue in GtkAda 3.8 - update

Rob Groen
In reply to this post by Dmitry A. Kazakov
When testing with my sample on Ubuntu 14.04 no problems were found, in agreement with what was found by Emmanuel regarding his tests on OSX (thanks for trying).

In Win7 (both 64 and 32 bit versions) using GNAT GPL 2014 I played around bit with my test application, and found the following:
- stripping down the test program to only a GtkListStore is enough to reproduce the problem
- when commenting out in Gtk.Tree_Models.Get_String (body) the call to Interfaces.C.Strings.Free (A) (line 159) the problem disappears!
- when changing the body of Gtk.Tree_Models.Get_String with a Glib.Values.Get_String implementation the problem also disappears.

The GNAT version doesn't seem to matter, with the GNAT 2012 GPL version and Gtkada 3.8 my test program behaves the same.

My conclusion is that there is (still) interference with the memory allocation. Having found an apparent workaround, on Win7 I will use a patched version of GtkAda3.8.

I am interested though, if anyone using the same configuration (Win7, GNAT GPL) can reproduce my scenario. See the test sample

Regards, Rob

On 29-06-14 19:30, Dmitry A. Kazakov wrote:
On Sun, 29 Jun 2014 18:11:33 +0200, you wrote:

As a follow up on the discussion last March wrt memory allocation
problems in GtkAda 3.x, I tried one of my failing programs with Gtkada
3.8. Unfortunately with the same result. 

I tried this on Windows 7, both on a 64- and on a 32-bit environment,
using the GNAT GPL 2014 compiler. In order to track the problem I
stripped my original application to a simple window with a treeview /
liststore, consisting of one column of type Gtype_String. The liststore
gets loaded with a nr of strings, then a search in the store is
performed. In the search a Get_String is done on an element of the
store. 

When an allocator is used prior searching ( sp := new String'("") ), the
program crashes after a few searches. When either the allocator or the
Get_String is omitted the program runs to completion.
(The nr of strings to put into the store and the nr of searches vary
with the code, logging statements, etc etc. The current nrs are those
that crashes the program in my environments, Win7 32- and 64-bit.) 

For those who want to research / replay this issue a zip file with the
code and a .gpr file can be found at:
http://robgr.home.xs4all.nl/gtkada3x_bug.zip. The "offending" code is in
the file gtkada3x_bug_support.adb.
Unfortunately I do not have the knowledge to research this problem. 
If I correctly remember, I might be wrong, the problem is with the Set
procedure of Gtk_List_Store with a string argument.

A workaround is to use Set_Value instead. You do Init of a GValue with
GType_String. Set the string into it. Then Set_Value to update the list
store and, finally, Unset the GValue object.



_______________________________________________
gtkada mailing list
[hidden email]
http://lists.adacore.com/mailman/listinfo/gtkada