Add protect code for curl handle
[platform/core/uifw/dali-adaptor.git] / dali / internal / imaging / common / file-download.cpp
old mode 100644 (file)
new mode 100755 (executable)
index 5875156..e384a50
@@ -174,7 +174,7 @@ bool DownloadFile( CURL* curlHandle,
 
   if( result != CURLE_OK)
   {
-    DALI_LOG_WARNING( "Failed to download http header for \"%s\" with error code %d\n", url.c_str(), result );
+    DALI_LOG_ERROR( "Failed to download http header for \"%s\" with error code %d\n", url.c_str(), result );
     return false;
   }
 
@@ -184,7 +184,7 @@ bool DownloadFile( CURL* curlHandle,
 
   if( size >= maximumAllowedSizeBytes )
   {
-    DALI_LOG_WARNING( "File content length %f > max allowed %zu \"%s\" \n", size, maximumAllowedSizeBytes, url.c_str() );
+    DALI_LOG_ERROR( "File content length %f > max allowed %zu \"%s\" \n", size, maximumAllowedSizeBytes, url.c_str() );
     return false;
   }
   else if( size > 0 )
@@ -200,7 +200,7 @@ bool DownloadFile( CURL* curlHandle,
 
   if( result != CURLE_OK )
   {
-    DALI_LOG_WARNING( "Failed to download image file \"%s\" with error code %d\n", url.c_str(), result );
+    DALI_LOG_ERROR( "Failed to download image file \"%s\" with error code %d\n", url.c_str(), result );
     return false;
   }
   return true;
@@ -287,6 +287,8 @@ bool DownloadRemoteFileIntoMemory( const std::string& url,
                                    size_t& dataSize,
                                    size_t maximumAllowedSizeBytes )
 {
+  bool result = false;
+
   if( url.empty() )
   {
     DALI_LOG_WARNING("empty url requested \n");
@@ -297,17 +299,18 @@ bool DownloadRemoteFileIntoMemory( const std::string& url,
   // thread we need to explicity call curl_global_init() on startup from a single thread.
 
   CURL* curlHandle = curl_easy_init();
+  if ( curlHandle )
+  {
+    result = DownloadFile( curlHandle, url, dataBuffer,  dataSize, maximumAllowedSizeBytes);
 
-  bool result = DownloadFile( curlHandle, url, dataBuffer,  dataSize, maximumAllowedSizeBytes);
-
-  // clean up session
-  curl_easy_cleanup( curlHandle );
+    // clean up session
+    curl_easy_cleanup( curlHandle );
 
 #ifdef TPK_CURL_ENABLED
-  // Clean up tpkp(the module for certificate pinning) resources on Tizen
-  tpkp_curl_cleanup();
+    // Clean up tpkp(the module for certificate pinning) resources on Tizen
+    tpkp_curl_cleanup();
 #endif // TPK_CURL_ENABLED
-
+  }
   return result;
 }