From 707f64b85c8a1b88923617ff72bd8a4ca562f3bd Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Wed, 16 Dec 2009 15:09:55 +0100 Subject: prevent destructors from throwing exceptions; check curl_easy_init errors Signed-off-by: Denys Vlasenko --- lib/Plugins/Catcut.cpp | 9 +-------- lib/Plugins/FileTransfer.cpp | 8 ++------ lib/Plugins/KerneloopsReporter.cpp | 4 ++-- lib/Plugins/SQLite3.cpp | 13 ++++++++++++- lib/Plugins/TicketUploader.cpp | 8 ++------ 5 files changed, 19 insertions(+), 23 deletions(-) (limited to 'lib/Plugins') diff --git a/lib/Plugins/Catcut.cpp b/lib/Plugins/Catcut.cpp index 35f56f2..a56015d 100644 --- a/lib/Plugins/Catcut.cpp +++ b/lib/Plugins/Catcut.cpp @@ -1,6 +1,3 @@ -#include -#include -#include #include "abrtlib.h" #include "abrt_xmlrpc.h" #include "Catcut.h" @@ -18,11 +15,7 @@ using namespace std; static int put_stream(const char *pURL, FILE* f, size_t content_length) { - CURL* curl = curl_easy_init(); - if (!curl) - { - throw CABRTException(EXCEP_PLUGIN, "put_stream: can't initialize curl library"); - } + CURL* curl = xcurl_easy_init(); /* enable uploading */ curl_easy_setopt(curl, CURLOPT_UPLOAD, 1L); /* specify target */ diff --git a/lib/Plugins/FileTransfer.cpp b/lib/Plugins/FileTransfer.cpp index 08bba6c..60e1e66 100644 --- a/lib/Plugins/FileTransfer.cpp +++ b/lib/Plugins/FileTransfer.cpp @@ -35,8 +35,8 @@ #include #include #include -#include #include "abrtlib.h" +#include "abrt_xmlrpc.h" /* for xcurl_easy_init */ #include "FileTransfer.h" #include "DebugDump.h" #include "ABRTException.h" @@ -85,11 +85,7 @@ void CFileTransfer::SendFile(const char *pURL, const char *pFilename) fclose(f); throw CABRTException(EXCEP_PLUGIN, "Can't stat archive file '%s'", pFilename); } - curl = curl_easy_init(); - if (!curl) - { - throw CABRTException(EXCEP_PLUGIN, "Curl library init error"); - } + curl = xcurl_easy_init(); /* enable uploading */ curl_easy_setopt(curl, CURLOPT_UPLOAD, 1L); /* specify target */ diff --git a/lib/Plugins/KerneloopsReporter.cpp b/lib/Plugins/KerneloopsReporter.cpp index 26430be..5cb525b 100644 --- a/lib/Plugins/KerneloopsReporter.cpp +++ b/lib/Plugins/KerneloopsReporter.cpp @@ -25,9 +25,9 @@ */ #include "abrtlib.h" +#include "abrt_xmlrpc.h" /* for xcurl_easy_init */ #include "KerneloopsReporter.h" #include "CommLayerInner.h" -#include #include "ABRTException.h" #define FILENAME_KERNELOOPS "kerneloops" @@ -64,7 +64,7 @@ static int http_post_to_kerneloops_site(const char *url, const char *oopsdata) struct curl_httppost *post = NULL; struct curl_httppost *last = NULL; - handle = curl_easy_init(); + handle = xcurl_easy_init(); curl_easy_setopt(handle, CURLOPT_URL, url); curl_formadd(&post, &last, diff --git a/lib/Plugins/SQLite3.cpp b/lib/Plugins/SQLite3.cpp index 12f8a5d..1979f24 100644 --- a/lib/Plugins/SQLite3.cpp +++ b/lib/Plugins/SQLite3.cpp @@ -238,7 +238,18 @@ CSQLite3::CSQLite3() : CSQLite3::~CSQLite3() { - DisConnect(); + /* Paranoia. In C++, destructor will abort() if it was called while unwinding + * the stack and it throws an exception. + */ + try + { + DisConnect(); + m_sDBPath.clear(); + } + catch (...) + { + error_msg_and_die("Internal error"); + } } void CSQLite3::DisConnect() diff --git a/lib/Plugins/TicketUploader.cpp b/lib/Plugins/TicketUploader.cpp index 14f5e1d..a4fe0e8 100644 --- a/lib/Plugins/TicketUploader.cpp +++ b/lib/Plugins/TicketUploader.cpp @@ -20,8 +20,8 @@ #include #include #include -#include #include "abrtlib.h" +#include "abrt_xmlrpc.h" /* for xcurl_easy_init */ #include "TicketUploader.h" #include "DebugDump.h" #include "ABRTException.h" @@ -124,11 +124,7 @@ void CTicketUploader::SendFile(const char *pURL, const char *pFilename) { throw CABRTException(EXCEP_PLUGIN, "Can't stat archive file '%s'", pFilename); } - CURL* curl = curl_easy_init(); - if (!curl) - { - throw CABRTException(EXCEP_PLUGIN, "Curl library init error"); - } + CURL* curl = xcurl_easy_init(); /* enable uploading */ curl_easy_setopt(curl, CURLOPT_UPLOAD, 1L); /* specify target */ -- cgit