[vlc-devel] [PATCH 22/41] Implement OS/2 specific initialization

Rémi Denis-Courmont remi at remlab.net
Tue Oct 11 13:35:50 CEST 2011


On Tue, 11 Oct 2011 20:18:08 +0900, KO Myung-Hun <komh78 at gmail.com> wrote:
>>> +void system_Init( void )
>>> +{
>>> +    PPIB ppib;
>>> +    CHAR psz_path[ CCHMAXPATH ];
>>> +    PSZ  psz_dirsep;
>>> +
>>> +    DosGetInfoBlocks( NULL, &ppib );
>>> +
>>> +    DosQueryModuleName( ppib->pib_hmte, sizeof( psz_path ), psz_path
);
>>> +
>>> +    /* remove the executable name */
>>> +    psz_dirsep = strrchr( psz_path, '\\');
>>> +    if( psz_dirsep )
>>> +        *psz_dirsep = '\0';
>>> +
>>> +    /* remove the last directory, i.e, \\bin */
>>> +    psz_dirsep = strrchr( psz_path, '\\' );
>>> +    if( psz_dirsep )
>>> +        *psz_dirsep = '\0';
>>> +
>>> +    asprintf( &psz_vlcpath, "%s\\lib\\vlc", psz_path );
>> 
>> This works for VLC. I don't mind but this may be a problem with LibVLC,
>> as
>> system_Init() may be entered multiple tines.
>> 
> 
> I don't understand why this may be a problem when being entered multiple
> times.

If system_Init() is called multiple times, asprintf() will overwrite the
psz_vlcpath value. This will result in a memory leak of the previous value.
Also there is a race condition.

Maybe in VLC 1.3 will be enhanced so that system_Init() is not re-entrant
but it is not done yet.

> And LibVLC call system_Init() many times without system_End() ?

It can happen if the application creates multiple instances with
libvlc_new().

Maybe you don't care about this on OS/2.

-- 
Rémi Denis-Courmont
http://www.remlab.net/



More information about the vlc-devel mailing list