1. iup memory leak - ping ghaberek

As you are probably aware, many of the routines in iup have obvious memory leaks, eg:

public procedure IupSetAttribute(atom ih, object name = NULL, object value = NULL) 
    if sequence(name) then name = allocate_string(name,1) end if   -- fine 
    if sequence(value) then value = allocate_string(value) end if  -- oops 
    c_proc( xIupSetAttribute, {ih,name,value} ) 
end procedure 

(FYI, I have completely rewritten the IUP wrapper for Phix: since that has a string type that can be passed directly to C funcs there is no need to call allocate_string, plus I wanted to learn/test/document each routine as I went along.)

Now, and this is the real trigger for this post, having fixed that memory leak I found that the icons in your editor were not being displayed.

It was a bit of a slog to track down but the problem was it was using IupSetAttribute() to save the results of get_image(), which needed to be changed to IupSetStrAttribute().

HTH,
Pete

new topic     » topic index » view message » categorize

2. Re: iup memory leak - ping ghaberek

petelomax said...

As you are probably aware, many of the routines in iup have obvious memory leaks, eg:

This was done on purpose for the time being. IIRC, freeing the value caused null pointer problems in my initial testing. I have an ifdef called USE_CLEANUP that, when defined, provides an optional integer cleanup = 0 parameter to all of the routines that allocate memory. It's quite unpleasant and I hadn't gotten back to deeper testing.

petelomax said...

(FYI, I have completely rewritten the IUP wrapper for Phix: since that has a string type that can be passed directly to C funcs there is no need to call allocate_string, plus I wanted to learn/test/document each routine as I went along.)

Neat! Did you write this by hand or did you adapt my wrapper? I'll admit my wrapper code is quite kludge-y.

petelomax said...

Now, and this is the real trigger for this post, having fixed that memory leak I found that the icons in your editor were not being displayed.

It was a bit of a slog to track down but the problem was it was using IupSetAttribute() to save the results of get_image(), which needed to be changed to IupSetStrAttribute().

That's probably been the problem all along. I didn't realize there were separate functions for setting string attributes. I can adapt the wrapper accordingly. Thanks for the heads up.

I have opened a new issue for this: https://bitbucket.org/ghaberek/iup4eu/issues/8/iupsetattribute-should-call

-Greg

new topic     » goto parent     » topic index » view message » categorize

3. Re: iup memory leak - ping ghaberek

ghaberek said...

Did you write this by hand or did you adapt my wrapper?

By hand. Bit of a slog but I probably spend ten times as long writing the docs as each function.

ghaberek said...

I didn't realize there were separate functions for setting string attributes. I can adapt the wrapper accordingly. Thanks for the heads up.

IupSetAttribute can store handles etc, or pointers to strings, which must therefore persist for the duration.
IupSetStrAttribute can only store strings, and makes an internal copy, so the app can bin 'em.

It would probably be fine for iup.e to use IupSetStrAttribute (internally) for all strings and IupSetAttribute for any atoms; I doubt the extra overhead of that internal duplication would be noticed very often if at all.

Pete

new topic     » goto parent     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu