From: chris <spamoff.danx@ntlworld.com>
Subject: Free-ing memory: not springing leaks?
Date: Sat, 13 Sep 2003 23:33:32 +0200
Date: 2003-09-13T23:33:32+02:00 [thread overview]
Message-ID: <2TM8b.1013$Nb6.297@newsfep4-winn.server.ntli.net> (raw)
Hi,
When you bind to c code, how do you deal with memory? I bound to a
function in Lua,
function Lua_Version return ICS.Chars_Ptr;
pragma Import (C, Lua_Version);
but upon free-ing the memory it gave a storage_error.
function Version return String is
X : ICS.Chars_Ptr := Lua_Version;
begin
declare
Y : String := ICS.Value (X);
begin
ICS.Free (X);
return Y;
end;
end Version;
To be clear, my understanding of this code is it get's a ptr to a null
terminated string from Lua_Version, get's that value as a string, frees
the null terminated string and returns the ada string. Clearly,
something is wrong with my understanding of how this works; if you free
the memory it gives a storage error.
How then, do you deal with memory leaks? If you bind to a c function
and it allocates a chunk of memory and returns it, how do get rid of it
and not cause leaks? Remove Free and no error occurs. Perhaps this is
a special case?
I vaguely recall reading somewhere that in general you shouldn't free C
allocated memory from Ada, but perhaps I was mistaken?
Can anyone please help with some advice or clarification? I have only
ever preallocated memory, passed it to a C function and released it
afterwards (e.g. to pass strings into C functions) not had memory given
by a c function and tried to release it.
Thanks,
Chris
next reply other threads:[~2003-09-13 21:33 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2003-09-13 21:33 chris [this message]
2003-09-14 1:10 ` Free-ing memory: not springing leaks? Matthew Heaney
2003-09-14 11:02 ` chris
2003-09-14 12:51 ` Matthew Heaney
2003-09-14 12:14 ` chris
2003-09-14 14:24 ` Ludovic Brenta
2003-09-14 19:00 ` chris
2003-09-14 16:06 ` Simon Wright
2003-09-15 7:13 ` Martin Krischik
2003-09-18 20:15 ` Warren W. Gay VE3WWG
2003-09-19 3:02 ` Hyman Rosen
2003-09-19 13:07 ` Warren W. Gay VE3WWG
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox