Page 1 of 1

libvlc : API to free tracks info

Posted: 23 Sep 2010 17:23
by pogo11
I'm not sure if this is the right place to suggest this feature, since it's about libvlc and not directly VLC.

The function libvlc_media_get_tracks_info allocates memory for the returned tracks info that must be freed by the caller. I suggest/request the addition of a function such as:

Code: Select all

VLC_PUBLIC_API int libvlc_media_free_tracks_info(libvlc_media_track_info_t *tracks );
that would free the memory.

The reason why I think this could be useful, aside from the possibility to change the way memory is allocated/freed inside libvlc without having to change client code, is the following. I've been using libvlc with an application compiled with Visual Studio (I know that __building VLC__ with Visual Studio is a complicated/not recommended thing, but using libvlc with it works great). When it comes the time to call free() on the allocated memory, Visual Studio's version of free() is called instead of mingw's, which crashes. In order to fix this, I had to create another DLL that I compiled with mingw with the very simple following code:

Code: Select all

#include <stdlib.h> void mingw_free( void * p ) { free( p ); }
I can dynamically load that DLL and the mingw_free() function pointer, in order to call mingw's version of free(). It's not that dirty of a workaround, but still I think that memory allocated by a library should be freed by that same library.

That's why I request a function to free the memory allocated by the function:

Code: Select all

VLC_PUBLIC_API int libvlc_media_free_tracks_info(libvlc_media_track_info_t *tracks );
If that is considered relevant, I could probably write a (about 10 lines long) patch.

Thanks,

pogo11

Re: libvlc : API to free tracks info

Posted: 24 Sep 2010 00:34
by Jean-Baptiste Kempf
I fear the crash is because of the freeing of the union.

Patches should be sent to vlc-devel@

Re: libvlc : API to free tracks info

Posted: 07 Jan 2011 20:15
by rzar
Hi, I also faced this problem - freeing the memory allocated inside libvlc.
I was trying to call that function from C#, and I concerned if that is right way to free memory :

[DllImport("libvlc", ExactSpelling = true, EntryPoint = "free")]
public static extern int libvlc_free(IntPtr ptr);

It doesn't crash, but it'll be better to have documented exported function for this operation. I see two ways to solve that:
1. Let the caller to allocate memory, so first call to libvlc_media_get_tracks_info function with zero pointer will return count, and second call with allocated memory will return array of tracks, copied to memory allocated by the caller.
2. Create new exported function like libvlc_media_free_tracks_info.