[Geany-devel] Use of MIO in tagmanager

Colomban Wendling lists.ban at xxxxx
Mon Oct 17 16:47:24 UTC 2011


(sorry for the delay)

Le 13/10/2011 09:33, Matthew Brush a écrit :
> On 10/12/2011 10:43 PM, Lex Trotman wrote:
>>
>> In tagmanager/read.c line 322 mio_new_memory is called without a free
>> function.  But I got lost in the multiple indirections trying to check
>> if there is a default free function.
>>
>> Otherwise it looks like this buffer may not be freed?
>>
> 
> It seems to get allocated via tm_source_file.c:210 and freed through
> tm_source_file.c:220.  bufferClose() is a macro for fileClose()  and
> mio_free() seems to be called there (read.c:357).

Exactly.

Actually there is no free function because the MIO object don't own the
buffer, so it has no reason to free it.  This is not really "good" in
theory since the user must not free the buffer until the MIO created at
this point is freed, but since the buffer isn't copied there's not
really any other solution -- and copying it would be quite stupid IMO.
And in practice, the code using bufferOpen() and bufferClose() is
careful of not doing anything wrong, so it's OK.

Actually the buffer itself is allocated in document.c:2265 and freed two
lines below.

Does it answer your question?

Cheers,
Colomban



More information about the Devel mailing list