denemo-devel
[Top][All Lists]
Advanced

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

Re: [Denemo-devel] Midi shortcuts


From: Richard Shann
Subject: Re: [Denemo-devel] Midi shortcuts
Date: Tue, 10 May 2011 18:33:42 +0100

On Sun, 2011-05-08 at 11:39 +0200, R. Mattes wrote:
> BTW,  my code example is longer than it needs to be, there's no need
> to establish a dynamic context at all - I was fooled by the original
> code. No idea why there's  scm_dynwind_... at all. No need for it.

Jeremiah - Ralf is confirming my suspicions here - I think we should
simply be calling g_free() on the strings that we have created on the
heap. I am not sure what scm_dynwind_... is for, if it is doing anything
it is only saving us the effort of writing those g_free() calls before
returning.
Even more surprising, I have looked into what is happening with the
scm_take_from_locale_string/n calls. In principle guile should be
freeing the passed string when it is finished with it. And since some of
these do not belong to the caller this should spell disaster. But
looking in the in the process table I see that the memory is actually
being gobbled up, not freed:

After creating

(d-InsertA)
(d-DirectivePut-chord-postfix "test" "Test text - should be double freed
by the scm_take_locale_stringn call")

then this script

(let loop ((count 0))
        (if (< count 1000000)
                (begin
                        (d-DirectiveGet-chord-postfix "test")
                        (loop (+ 1 count)))))

gobbles up memory each time it is called. This is despite the _take_
form being used in view.c to return the value to
d-DirectiveGet-chord-postfix the code is in view.c thus ...


 extern gchar *what##_directive_get_tag (gchar *tagname);\
  gchar *val = (gchar*)what##_directive_get_tag (tagname);\
  if(val){\
    scm_dynwind_end();\
    return scm_take_locale_stringn (val, strlen(val)); ...

where what## is chord in this case.

So instead of double free, we get a copy being made, and that not being
freed at all.

If you or anyone can shed some light on this I would be a happy bunny.

Richard





reply via email to

[Prev in Thread] Current Thread [Next in Thread]