From 6ac9f02b2695ffe2f8a8107be74ccb67f9c70b5d Mon Sep 17 00:00:00 2001 From: aymeric Date: Sat, 28 Mar 2009 14:24:43 +0000 Subject: [PATCH] fix descriptor leak and crash when image is 0 sized. git-svn-id: svn+ssh://svn.savannah.nongnu.org/linphone/trunk@377 3f6dc0c8-ddfe-455d-9043-3cd528dc4637 --- linphone/mediastreamer2/src/nowebcam.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/linphone/mediastreamer2/src/nowebcam.c b/linphone/mediastreamer2/src/nowebcam.c index 7fb055d5a..6b15f0f92 100644 --- a/linphone/mediastreamer2/src/nowebcam.c +++ b/linphone/mediastreamer2/src/nowebcam.c @@ -83,7 +83,27 @@ mblk_t *ms_load_jpeg_as_yuv(const char *jpgpath, MSVideoSize *reqsize){ #endif if (fd!=-1){ fstat(fd,&statbuf); + if (statbuf.st_size<=0) + { +#if !defined(_MSC_VER) + close(fd); +#else + _close(fd); +#endif + ms_error("Cannot load %s",jpgpath); + return NULL; + } jpgbuf=(uint8_t*)alloca(statbuf.st_size); + if (jpgbuf==NULL) + { +#if !defined(_MSC_VER) + close(fd); +#else + _close(fd); +#endif + ms_error("Cannot allocate buffer for %s",jpgpath); + return NULL; + } #if !defined(_MSC_VER) read(fd,jpgbuf,statbuf.st_size); #else @@ -93,6 +113,11 @@ mblk_t *ms_load_jpeg_as_yuv(const char *jpgpath, MSVideoSize *reqsize){ }else{ ms_error("Cannot load %s",jpgpath); } +#if !defined(_MSC_VER) + close(fd); +#else + _close(fd); +#endif return m; }