[FFmpeg-cvslog] avformat/network: Check for av_malloc* failures in ff_tls_init()

Michael Niedermayer git at videolan.org
Tue Feb 3 02:36:04 CET 2015


ffmpeg | branch: master | Michael Niedermayer <michaelni at gmx.at> | Thu Jan 22 15:50:48 2015 +0100| [7620d48f2eab67812d8c535d12a98eaa754a1177] | committer: Michael Niedermayer

avformat/network: Check for av_malloc* failures in ff_tls_init()

Signed-off-by: Michael Niedermayer <michaelni at gmx.at>

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=7620d48f2eab67812d8c535d12a98eaa754a1177
---

 libavformat/network.c |    6 +++++-
 libavformat/network.h |    2 +-
 libavformat/tls.c     |    3 ++-
 libavformat/utils.c   |    3 ++-
 4 files changed, 10 insertions(+), 4 deletions(-)

diff --git a/libavformat/network.c b/libavformat/network.c
index 9f02ec6..e9eab29 100644
--- a/libavformat/network.c
+++ b/libavformat/network.c
@@ -66,7 +66,7 @@ GCRY_THREAD_OPTION_PTHREAD_IMPL;
 #endif
 #endif
 
-void ff_tls_init(void)
+int ff_tls_init(void)
 {
     avpriv_lock_avformat();
 #if CONFIG_OPENSSL
@@ -77,6 +77,8 @@ void ff_tls_init(void)
         if (!CRYPTO_get_locking_callback()) {
             int i;
             openssl_mutexes = av_malloc_array(sizeof(pthread_mutex_t), CRYPTO_num_locks());
+            if (!openssl_mutexes)
+                return AVERROR(ENOMEM);
             for (i = 0; i < CRYPTO_num_locks(); i++)
                 pthread_mutex_init(&openssl_mutexes[i], NULL);
             CRYPTO_set_locking_callback(openssl_lock);
@@ -96,6 +98,8 @@ void ff_tls_init(void)
     gnutls_global_init();
 #endif
     avpriv_unlock_avformat();
+
+    return 0;
 }
 
 void ff_tls_deinit(void)
diff --git a/libavformat/network.h b/libavformat/network.h
index 0d1081a..86fb656 100644
--- a/libavformat/network.h
+++ b/libavformat/network.h
@@ -78,7 +78,7 @@ extern int ff_network_inited_globally;
 int ff_network_init(void);
 void ff_network_close(void);
 
-void ff_tls_init(void);
+int ff_tls_init(void);
 void ff_tls_deinit(void);
 
 int ff_network_wait_fd(int fd, int write);
diff --git a/libavformat/tls.c b/libavformat/tls.c
index d6a6be3..942083b 100644
--- a/libavformat/tls.c
+++ b/libavformat/tls.c
@@ -175,7 +175,8 @@ static int tls_open(URLContext *h, const char *uri, int flags)
     const char *proxy_path;
     int use_proxy;
 
-    ff_tls_init();
+    if ((ret = ff_tls_init()) < 0)
+        return ret;
 
     if (c->listen)
         snprintf(opts, sizeof(opts), "?listen=1");
diff --git a/libavformat/utils.c b/libavformat/utils.c
index bbb1cf7..570603a 100644
--- a/libavformat/utils.c
+++ b/libavformat/utils.c
@@ -4095,7 +4095,8 @@ int avformat_network_init(void)
     ff_network_inited_globally = 1;
     if ((ret = ff_network_init()) < 0)
         return ret;
-    ff_tls_init();
+    if ((ret = ff_tls_init()) < 0)
+        return ret;
 #endif
     return 0;
 }



More information about the ffmpeg-cvslog mailing list