libvlc : API to free tracks info

This forum is about all development around libVLC.
pogo11
New Cone
New Cone
Posts: 4
Joined: 21 Sep 2010 21:32

libvlc : API to free tracks info

Postby pogo11 » 23 Sep 2010 17:23

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

Jean-Baptiste Kempf
Site Administrator
Site Administrator
Posts: 37523
Joined: 22 Jul 2005 15:29
VLC version: 4.0.0-git
Operating System: Linux, Windows, Mac
Location: Cone, France
Contact:

Re: libvlc : API to free tracks info

Postby Jean-Baptiste Kempf » 24 Sep 2010 00:34

I fear the crash is because of the freeing of the union.

Patches should be sent to vlc-devel@
Jean-Baptiste Kempf
http://www.jbkempf.com/ - http://www.jbkempf.com/blog/category/Videolan
VLC media player developer, VideoLAN President and Sites administrator
If you want an answer to your question, just be specific and precise. Don't use Private Messages.

rzar
New Cone
New Cone
Posts: 8
Joined: 13 May 2009 13:54

Re: libvlc : API to free tracks info

Postby rzar » 07 Jan 2011 20:15

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.


Return to “Development around libVLC”

Who is online

Users browsing this forum: No registered users and 10 guests