[Mono-devel-list] reading char * from extern function
dietmar
dietmar at ximian.com
Fri May 23 02:53:17 EDT 2003
On Fri, 2003-05-23 at 02:56, Marcus wrote:
> Having the runtime automatically free the C-string seems very dangerous. Some
> functions might return a pointer to a string but also store the pointer
> elsewhere expecting that the string will remain allocated. Even worse, it's
> possible for a function to return a pointer to a statically-allocated string.
> (What happens in this case when the runtime tries to free the string?)
Well, thats true. Functions should simply duplicate the string before
they return if needed. Else you have a memory leak which is impossible
to avoid.
The questions is how the MS runtime handle that case?
>
> There is also a question about whether it is legal to mix malloc/free with the
> glib equivalents. (Last I asked, I could not get a definite answer.)
it should be no problem to mix them (g_free a malloced memory).
(yes - this is still no definite answer)
>
>
>
> tring was allocated using malloc, using some glib allocation function, or
>
> On Thursday 22 May 2003 3:27 am, dietmar wrote:
> > On Thu, 2003-05-22 at 09:31, md at mt.web.id wrote:
> > > situation:
> > > I have a C library. One of it's function is:
> > >
> > > char * some_func(int param, const char * param2) {
> > > the next question is: should I free() the retval? if yes, how to do
> > > that?
>
> > I guess the runtime should free the string for you, but we don't do that
> > currently. Somebody should test how MS handles this.
More information about the Mono-devel-list
mailing list