vlc/vlc-2.2 | branch: master | Hannes Domani <[email protected]> | Fri Aug 22 15:34:21 2014 +0200| [d0698491680ddda833690962052735368a9d8c9c] | committer: Rémi Denis-Courmont
lua: never change index of lua file descriptors Signed-off-by: Rémi Denis-Courmont <[email protected]> (cherry picked from commit 7d20cc0edf642d323ece1dc4163dae09a467da6f) > http://git.videolan.org/gitweb.cgi/vlc/vlc-2.2.git/?a=commit;h=d0698491680ddda833690962052735368a9d8c9c --- modules/lua/libs/net.c | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/modules/lua/libs/net.c b/modules/lua/libs/net.c index 5fc757a..913db5b 100644 --- a/modules/lua/libs/net.c +++ b/modules/lua/libs/net.c @@ -65,6 +65,15 @@ static int vlclua_fd_map( lua_State *L, int fd ) assert( dt->fdv[i] != fd ); #endif + for( unsigned i = 0; i < dt->fdc; i++ ) + { + if( dt->fdv[i] == -1 ) + { + dt->fdv[i] = fd; + return 3 + i; + } + } + if( dt->fdc >= 64 ) return -1; @@ -125,9 +134,9 @@ static void vlclua_fd_unmap( lua_State *L, unsigned idx ) return; fd = dt->fdv[idx]; - dt->fdc--; - memmove( dt->fdv + idx, dt->fdv + idx + 1, - (dt->fdc - idx) * sizeof (dt->fdv[0]) ); + dt->fdv[idx] = -1; + while( dt->fdc > 0 && dt->fdv[dt->fdc - 1] == -1 ) + dt->fdc--; /* realloc() not really needed */ #ifndef NDEBUG for( unsigned i = 0; i < dt->fdc; i++ ) @@ -537,7 +546,8 @@ void vlclua_fd_interrupt( vlclua_dtable_t *dt ) void vlclua_fd_cleanup( vlclua_dtable_t *dt ) { for( unsigned i = 0; i < dt->fdc; i++ ) - net_Close( dt->fdv[i] ); + if( dt->fdv[i] != -1 ) + net_Close( dt->fdv[i] ); free( dt->fdv ); #ifndef _WIN32 if( dt->fd[1] != -1 ) _______________________________________________ vlc-commits mailing list [email protected] https://mailman.videolan.org/listinfo/vlc-commits
