1
0
mirror of https://github.com/mpv-player/mpv synced 2025-02-28 11:20:56 +00:00

Check for fork failing and make sure cache_uninit always frees the cache data

even if fork failed.


git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@30393 b3059339-0415-0410-9bf9-f77b7e298cf2
This commit is contained in:
reimar 2010-01-23 10:50:50 +00:00
parent a281ccb094
commit 7afaecc111

View File

@ -15,6 +15,7 @@
#include <signal.h> #include <signal.h>
#include <sys/types.h> #include <sys/types.h>
#include <unistd.h> #include <unistd.h>
#include <errno.h>
#include "osdep/shmem.h" #include "osdep/shmem.h"
#include "osdep/timer.h" #include "osdep/timer.h"
@ -284,13 +285,14 @@ cache_vars_t* cache_init(int size,int sector){
void cache_uninit(stream_t *s) { void cache_uninit(stream_t *s) {
cache_vars_t* c = s->cache_data; cache_vars_t* c = s->cache_data;
if(!s->cache_pid) return; if(s->cache_pid) {
#if defined(__MINGW32__) || defined(PTHREAD_CACHE) || defined(__OS2__) #if defined(__MINGW32__) || defined(PTHREAD_CACHE) || defined(__OS2__)
cache_do_control(s, -2, NULL); cache_do_control(s, -2, NULL);
#else #else
kill(s->cache_pid,SIGKILL); kill(s->cache_pid,SIGKILL);
waitpid(s->cache_pid,NULL,0); waitpid(s->cache_pid,NULL,0);
#endif #endif
}
if(!c) return; if(!c) return;
#if defined(__MINGW32__) || defined(PTHREAD_CACHE) || defined(__OS2__) #if defined(__MINGW32__) || defined(PTHREAD_CACHE) || defined(__OS2__)
free(c->stream); free(c->stream);
@ -334,6 +336,8 @@ int stream_enable_cache(stream_t *stream,int size,int min,int seek_limit){
#if !defined(__MINGW32__) && !defined(PTHREAD_CACHE) && !defined(__OS2__) #if !defined(__MINGW32__) && !defined(PTHREAD_CACHE) && !defined(__OS2__)
if((stream->cache_pid=fork())){ if((stream->cache_pid=fork())){
if ((pid_t)stream->cache_pid == -1)
stream->cache_pid = 0;
#else #else
{ {
stream_t* stream2=malloc(sizeof(stream_t)); stream_t* stream2=malloc(sizeof(stream_t));
@ -351,6 +355,11 @@ int stream_enable_cache(stream_t *stream,int size,int min,int seek_limit){
} }
#endif #endif
#endif #endif
if (!stream->cache_pid) {
mp_msg(MSGT_CACHE, MSGL_ERR,
"Starting cache process/thread failed: %s.\n", strerror(errno));
return 0;
}
// wait until cache is filled at least prefill_init % // wait until cache is filled at least prefill_init %
mp_msg(MSGT_CACHE,MSGL_V,"CACHE_PRE_INIT: %"PRId64" [%"PRId64"] %"PRId64" pre:%d eof:%d \n", mp_msg(MSGT_CACHE,MSGL_V,"CACHE_PRE_INIT: %"PRId64" [%"PRId64"] %"PRId64" pre:%d eof:%d \n",
(int64_t)s->min_filepos,(int64_t)s->read_filepos,(int64_t)s->max_filepos,min,s->eof); (int64_t)s->min_filepos,(int64_t)s->read_filepos,(int64_t)s->max_filepos,min,s->eof);