From 5482e87e23f8fe889527a27376238dd3bf210b29 Mon Sep 17 00:00:00 2001 From: Fred Gleason Date: Mon, 30 Jul 2018 11:02:55 -0400 Subject: [PATCH] 2018-07-30 Fred Gleason * Cleaned up memory leaks in 'RDAudioExport', 'RDAudioImport', 'RDAudioStore', 'RDCart', 'RDCopyAudio', 'RDPeakExport', 'RDRehash', and 'RDTrimAudio'. * Modified Xload operations in 'RDDelete', 'RDDownload' and 'RDUpload' to work properly with credentials using UTF-8 strings. --- ChangeLog | 6 ++++++ lib/rdaudioexport.cpp | 8 ++++++++ lib/rdaudioimport.cpp | 6 +++++- lib/rdaudioinfo.cpp | 5 +++++ lib/rdaudiostore.cpp | 5 +++++ lib/rdcart.cpp | 2 ++ lib/rdcopyaudio.cpp | 4 ++++ lib/rddelete.cpp | 6 +++--- lib/rddownload.cpp | 6 +++--- lib/rdpeaksexport.cpp | 5 +++++ lib/rdpodcast.cpp | 7 ++++--- lib/rdrehash.cpp | 4 ++++ lib/rdtrimaudio.cpp | 4 ++++ lib/rdupload.cpp | 6 +++--- 14 files changed, 61 insertions(+), 13 deletions(-) diff --git a/ChangeLog b/ChangeLog index 2fb1d6e6..30f9cbcb 100644 --- a/ChangeLog +++ b/ChangeLog @@ -17269,3 +17269,9 @@ * Modified 'RDRehash' to use multipart-mime encoding. 2018-07-30 Fred Gleason * Modified 'RDTrimAudio' to use multipart-mime encoding. +2018-07-30 Fred Gleason + * Cleaned up memory leaks in 'RDAudioExport', 'RDAudioImport', + 'RDAudioStore', 'RDCart', 'RDCopyAudio', 'RDPeakExport', + 'RDRehash', and 'RDTrimAudio'. + * Modified Xload operations in 'RDDelete', 'RDDownload' and + 'RDUpload' to work properly with credentials using UTF-8 strings. diff --git a/lib/rdaudioexport.cpp b/lib/rdaudioexport.cpp index 2439797b..327ae711 100644 --- a/lib/rdaudioexport.cpp +++ b/lib/rdaudioexport.cpp @@ -196,6 +196,7 @@ RDAudioExport::ErrorCode RDAudioExport::runExport(const QString &username, (const char *)QString().sprintf("%u",conv_enable_metadata), CURLFORM_END); if((curl=curl_easy_init())==NULL) { + curl_formfree(first); return RDAudioExport::ErrorInternal; } if((f=fopen(conv_dst_filename,"w"))==NULL) { @@ -226,6 +227,7 @@ RDAudioExport::ErrorCode RDAudioExport::runExport(const QString &username, case CURLE_ABORTED_BY_CALLBACK: curl_easy_cleanup(curl); + curl_formfree(first); unlink(conv_dst_filename); return RDAudioExport::ErrorAborted; @@ -240,6 +242,7 @@ RDAudioExport::ErrorCode RDAudioExport::runExport(const QString &username, case CURLE_HTTP_POST_ERROR: default: curl_easy_cleanup(curl); + curl_formfree(first); return RDAudioExport::ErrorInternal; case CURLE_URL_MALFORMAT: @@ -247,6 +250,7 @@ RDAudioExport::ErrorCode RDAudioExport::runExport(const QString &username, case CURLE_COULDNT_CONNECT: case 9: // CURLE_REMOTE_ACCESS_DENIED: curl_easy_cleanup(curl); + curl_formfree(first); return RDAudioExport::ErrorUrlInvalid; } curl_easy_getinfo(curl,CURLINFO_RESPONSE_CODE,&response_code); @@ -255,6 +259,8 @@ RDAudioExport::ErrorCode RDAudioExport::runExport(const QString &username, if(response_code==200) { *conv_err=RDAudioConvert::ErrorOk; + curl_easy_cleanup(curl); + curl_formfree(first); return RDAudioExport::ErrorOk; } @@ -274,6 +280,8 @@ RDAudioExport::ErrorCode RDAudioExport::runExport(const QString &username, default: ret=RDAudioExport::ErrorConverter; } + curl_easy_cleanup(curl); + curl_formfree(first); unlink(conv_dst_filename); return ret; diff --git a/lib/rdaudioimport.cpp b/lib/rdaudioimport.cpp index 48e3c5fb..08a7985a 100644 --- a/lib/rdaudioimport.cpp +++ b/lib/rdaudioimport.cpp @@ -163,6 +163,7 @@ RDAudioImport::ErrorCode RDAudioImport::runImport(const QString &username, // Set up the transfer // if((curl=curl_easy_init())==NULL) { + curl_formfree(first); return RDAudioImport::ErrorInternal; } curl_easy_setopt(curl,CURLOPT_WRITEDATA,stdout); @@ -192,6 +193,7 @@ RDAudioImport::ErrorCode RDAudioImport::runImport(const QString &username, case CURLE_ABORTED_BY_CALLBACK: curl_easy_cleanup(curl); + curl_formfree(first); return RDAudioImport::ErrorAborted; case CURLE_UNSUPPORTED_PROTOCOL: @@ -203,8 +205,9 @@ RDAudioImport::ErrorCode RDAudioImport::runImport(const QString &username, case CURLE_OUT_OF_MEMORY: case CURLE_OPERATION_TIMEDOUT: case CURLE_HTTP_POST_ERROR: - curl_easy_cleanup(curl); default: + curl_easy_cleanup(curl); + curl_formfree(first); return RDAudioImport::ErrorInternal; case CURLE_URL_MALFORMAT: @@ -212,6 +215,7 @@ RDAudioImport::ErrorCode RDAudioImport::runImport(const QString &username, case CURLE_COULDNT_CONNECT: case 9: // CURLE_REMOTE_ACCESS_DENIED: curl_easy_cleanup(curl); + curl_formfree(first); return RDAudioImport::ErrorUrlInvalid; } /* diff --git a/lib/rdaudioinfo.cpp b/lib/rdaudioinfo.cpp index fb7de53c..f37dd4a6 100644 --- a/lib/rdaudioinfo.cpp +++ b/lib/rdaudioinfo.cpp @@ -138,6 +138,7 @@ RDAudioInfo::ErrorCode RDAudioInfo::runInfo(const QString &username, (const char *)QString().sprintf("%u",conv_cut_number), CURLFORM_END); if((curl=curl_easy_init())==NULL) { + curl_formfree(first); return RDAudioInfo::ErrorInternal; } // @@ -168,6 +169,7 @@ RDAudioInfo::ErrorCode RDAudioInfo::runInfo(const QString &username, case CURLE_OPERATION_TIMEDOUT: case CURLE_HTTP_POST_ERROR: curl_easy_cleanup(curl); + curl_formfree(first); fprintf(stderr,"curl error: %d\n",curl_err); return RDAudioInfo::ErrorInternal; @@ -176,14 +178,17 @@ RDAudioInfo::ErrorCode RDAudioInfo::runInfo(const QString &username, case CURLE_COULDNT_CONNECT: case 9: // CURLE_REMOTE_ACCESS_DENIED curl_easy_cleanup(curl); + curl_formfree(first); return RDAudioInfo::ErrorUrlInvalid; default: curl_easy_cleanup(curl); + curl_formfree(first); return RDAudioInfo::ErrorService; } curl_easy_getinfo(curl,CURLINFO_RESPONSE_CODE,&response_code); curl_easy_cleanup(curl); + curl_formfree(first); switch(response_code) { case 200: diff --git a/lib/rdaudiostore.cpp b/lib/rdaudiostore.cpp index 59b6eae0..6bbad127 100644 --- a/lib/rdaudiostore.cpp +++ b/lib/rdaudiostore.cpp @@ -89,6 +89,7 @@ RDAudioStore::ErrorCode RDAudioStore::runStore(const QString &username, curl_formadd(&first,&last,CURLFORM_PTRNAME,"PASSWORD", CURLFORM_COPYCONTENTS,(const char *)password,CURLFORM_END); if((curl=curl_easy_init())==NULL) { + curl_formfree(first); return RDAudioStore::ErrorInternal; } @@ -120,6 +121,7 @@ RDAudioStore::ErrorCode RDAudioStore::runStore(const QString &username, case CURLE_OPERATION_TIMEDOUT: case CURLE_HTTP_POST_ERROR: curl_easy_cleanup(curl); + curl_formfree(first); fprintf(stderr,"curl error: %d\n",curl_err); return RDAudioStore::ErrorInternal; @@ -128,14 +130,17 @@ RDAudioStore::ErrorCode RDAudioStore::runStore(const QString &username, case CURLE_COULDNT_CONNECT: case 9: // CURLE_REMOTE_ACCESS_DENIED curl_easy_cleanup(curl); + curl_formfree(first); return RDAudioStore::ErrorUrlInvalid; default: curl_easy_cleanup(curl); + curl_formfree(first); return RDAudioStore::ErrorService; } curl_easy_getinfo(curl,CURLINFO_RESPONSE_CODE,&response_code); curl_easy_cleanup(curl); + curl_formfree(first); switch(response_code) { case 200: diff --git a/lib/rdcart.cpp b/lib/rdcart.cpp index 8171441c..f0b3442e 100644 --- a/lib/rdcart.cpp +++ b/lib/rdcart.cpp @@ -1681,6 +1681,7 @@ bool RDCart::removeCutAudio(RDStation *station,RDUser *user,unsigned cart_num, (const char *)QString().sprintf("%u",RDCut::cutNumber(cutname)), CURLFORM_END); if((curl=curl_easy_init())==NULL) { + curl_formfree(first); return false; } // @@ -1700,6 +1701,7 @@ bool RDCart::removeCutAudio(RDStation *station,RDUser *user,unsigned cart_num, curl_easy_getinfo(curl,CURLINFO_RESPONSE_CODE,&response_code); ret&=response_code==200; curl_easy_cleanup(curl); + curl_formfree(first); } #endif // WIN32 return ret; diff --git a/lib/rdcopyaudio.cpp b/lib/rdcopyaudio.cpp index 7f727956..e1fb8453 100644 --- a/lib/rdcopyaudio.cpp +++ b/lib/rdcopyaudio.cpp @@ -108,6 +108,7 @@ RDCopyAudio::ErrorCode RDCopyAudio::runCopy(const QString &username, (const char *)QString().sprintf("%u",conv_destination_cut_number), CURLFORM_END); if((curl=curl_easy_init())==NULL) { + curl_formfree(first); return RDCopyAudio::ErrorInternal; } @@ -138,6 +139,7 @@ RDCopyAudio::ErrorCode RDCopyAudio::runCopy(const QString &username, case CURLE_HTTP_POST_ERROR: default: curl_easy_cleanup(curl); + curl_formfree(first); return RDCopyAudio::ErrorInternal; case CURLE_URL_MALFORMAT: @@ -145,10 +147,12 @@ RDCopyAudio::ErrorCode RDCopyAudio::runCopy(const QString &username, case CURLE_COULDNT_CONNECT: case 9: // CURLE_REMOTE_ACCESS_DENIED: curl_easy_cleanup(curl); + curl_formfree(first); return RDCopyAudio::ErrorUrlInvalid; } curl_easy_getinfo(curl,CURLINFO_RESPONSE_CODE,&response_code); curl_easy_cleanup(curl); + curl_formfree(first); switch(response_code) { case 200: diff --git a/lib/rddelete.cpp b/lib/rddelete.cpp index a7da4ab9..93efb6a3 100644 --- a/lib/rddelete.cpp +++ b/lib/rddelete.cpp @@ -98,15 +98,15 @@ RDDelete::ErrorCode RDDelete::runDelete(const QString &username, return RDDelete::ErrorInternal; } strncpy(urlstr,(const char *)(conv_target_url.protocol()+"://"+ - conv_target_url.host()+"/"),1024); + conv_target_url.host()+"/").utf8(),1024); curl_easy_setopt(curl,CURLOPT_URL,urlstr); - strncpy(userpwd,QString(username)+":"+password,256); + strncpy(userpwd,(QString(username)+":"+password).utf8(),256); curl_easy_setopt(curl,CURLOPT_USERPWD,userpwd); curl_easy_setopt(curl,CURLOPT_HTTPAUTH,CURLAUTH_ANY); curl_easy_setopt(curl,CURLOPT_WRITEFUNCTION,DeleteWriteCallback); curl_easy_setopt(curl,CURLOPT_WRITEDATA,&xml); curl_easy_setopt(curl,CURLOPT_USERAGENT, - (const char *)conv_config->userAgent()); + (const char *)conv_config->userAgent().utf8()); if(log_debug) { curl_easy_setopt(curl,CURLOPT_VERBOSE,1); curl_easy_setopt(curl,CURLOPT_DEBUGFUNCTION,DeleteErrorCallback); diff --git a/lib/rddownload.cpp b/lib/rddownload.cpp index 6ce86bd1..b0e77194 100644 --- a/lib/rddownload.cpp +++ b/lib/rddownload.cpp @@ -133,10 +133,10 @@ RDDownload::ErrorCode RDDownload::runDownload(const QString &username, // error. // strncpy(url,conv_src_url. - toString(conv_src_url.protocol().lower().left(4)=="http"),1024); + toString(conv_src_url.protocol().lower().left(4)=="http").utf8(),1024); curl_easy_setopt(curl,CURLOPT_URL,url); curl_easy_setopt(curl,CURLOPT_WRITEDATA,f); - strncpy(userpwd,username+":"+password,256); + strncpy(userpwd,(username+":"+password).utf8(),256); curl_easy_setopt(curl,CURLOPT_USERPWD,userpwd); curl_easy_setopt(curl,CURLOPT_TIMEOUT,RD_CURL_TIMEOUT); curl_easy_setopt(curl,CURLOPT_FOLLOWLOCATION,1); @@ -144,7 +144,7 @@ RDDownload::ErrorCode RDDownload::runDownload(const QString &username, curl_easy_setopt(curl,CURLOPT_PROGRESSDATA,this); curl_easy_setopt(curl,CURLOPT_NOPROGRESS,0); curl_easy_setopt(curl,CURLOPT_USERAGENT, - (const char *)conv_config->userAgent()); + (const char *)conv_config->userAgent().utf8()); if(log_debug) { curl_easy_setopt(curl,CURLOPT_VERBOSE,1); curl_easy_setopt(curl,CURLOPT_DEBUGFUNCTION,DownloadErrorCallback); diff --git a/lib/rdpeaksexport.cpp b/lib/rdpeaksexport.cpp index 1f7135b4..90c07efa 100644 --- a/lib/rdpeaksexport.cpp +++ b/lib/rdpeaksexport.cpp @@ -115,6 +115,7 @@ RDPeaksExport::ErrorCode RDPeaksExport::runExport(const QString &username, (const char *)QString().sprintf("%u",conv_cut_number), CURLFORM_END); if((curl=curl_easy_init())==NULL) { + curl_formfree(first); return RDPeaksExport::ErrorInternal; } curl_easy_setopt(curl,CURLOPT_WRITEDATA,this); @@ -140,6 +141,7 @@ RDPeaksExport::ErrorCode RDPeaksExport::runExport(const QString &username, case CURLE_ABORTED_BY_CALLBACK: curl_easy_cleanup(curl); + curl_formfree(first); return RDPeaksExport::ErrorAborted; case CURLE_UNSUPPORTED_PROTOCOL: @@ -153,6 +155,7 @@ RDPeaksExport::ErrorCode RDPeaksExport::runExport(const QString &username, case CURLE_HTTP_POST_ERROR: default: curl_easy_cleanup(curl); + curl_formfree(first); return RDPeaksExport::ErrorInternal; case CURLE_URL_MALFORMAT: @@ -160,10 +163,12 @@ RDPeaksExport::ErrorCode RDPeaksExport::runExport(const QString &username, case CURLE_COULDNT_CONNECT: case 9: // CURLE_REMOTE_ACCESS_DENIED curl_easy_cleanup(curl); + curl_formfree(first); return RDPeaksExport::ErrorUrlInvalid; } curl_easy_getinfo(curl,CURLINFO_RESPONSE_CODE,&response_code); curl_easy_cleanup(curl); + curl_formfree(first); switch(response_code) { case 200: diff --git a/lib/rdpodcast.cpp b/lib/rdpodcast.cpp index 6c4fc5f5..be2f5014 100644 --- a/lib/rdpodcast.cpp +++ b/lib/rdpodcast.cpp @@ -309,13 +309,14 @@ bool RDPodcast::removeAudio(RDFeed *feed,QString *err_text,bool log_debug) const return false; } url=new QUrl(feed->purgeUrl()); - strncpy(urlstr,(const char *)(url->protocol()+"://"+url->host()+"/"),1024); + strncpy(urlstr,(const char *)(url->protocol()+"://"+url->host()+"/").utf8(), + 1024); curl_easy_setopt(curl,CURLOPT_URL,urlstr); - strncpy(userpwd,feed->purgeUsername()+":"+feed->purgePassword(),256); + strncpy(userpwd,(feed->purgeUsername()+":"+feed->purgePassword()).utf8(),256); curl_easy_setopt(curl,CURLOPT_USERPWD,userpwd); curl_easy_setopt(curl,CURLOPT_HTTPAUTH,CURLAUTH_ANY); curl_easy_setopt(curl,CURLOPT_USERAGENT, - (const char *)podcast_config->userAgent()); + (const char *)podcast_config->userAgent().utf8()); if(log_debug) { curl_easy_setopt(curl,CURLOPT_VERBOSE,1); curl_easy_setopt(curl,CURLOPT_DEBUGFUNCTION,PodcastErrorCallback); diff --git a/lib/rdrehash.cpp b/lib/rdrehash.cpp index 574ac8ad..8218632d 100644 --- a/lib/rdrehash.cpp +++ b/lib/rdrehash.cpp @@ -93,6 +93,7 @@ RDRehash::ErrorCode RDRehash::runRehash(const QString &username, (const char *)QString().sprintf("%u",conv_cut_number), CURLFORM_END); if((curl=curl_easy_init())==NULL) { + curl_formfree(first); return RDRehash::ErrorInternal; } @@ -123,6 +124,7 @@ RDRehash::ErrorCode RDRehash::runRehash(const QString &username, case CURLE_OPERATION_TIMEDOUT: case CURLE_HTTP_POST_ERROR: curl_easy_cleanup(curl); + curl_formfree(first); fprintf(stderr,"curl error: %d\n",curl_err); return RDRehash::ErrorInternal; @@ -131,6 +133,7 @@ RDRehash::ErrorCode RDRehash::runRehash(const QString &username, case CURLE_COULDNT_CONNECT: case 9: // CURLE_REMOTE_ACCESS_DENIED curl_easy_cleanup(curl); + curl_formfree(first); return RDRehash::ErrorUrlInvalid; default: @@ -139,6 +142,7 @@ RDRehash::ErrorCode RDRehash::runRehash(const QString &username, } curl_easy_getinfo(curl,CURLINFO_RESPONSE_CODE,&response_code); curl_easy_cleanup(curl); + curl_formfree(first); switch(response_code) { case 200: diff --git a/lib/rdtrimaudio.cpp b/lib/rdtrimaudio.cpp index 7cb1994b..70db4900 100644 --- a/lib/rdtrimaudio.cpp +++ b/lib/rdtrimaudio.cpp @@ -121,6 +121,7 @@ RDTrimAudio::ErrorCode RDTrimAudio::runTrim(const QString &username, (const char *)QString().sprintf("%u",conv_trim_level), CURLFORM_END); if((curl=curl_easy_init())==NULL) { + curl_formfree(first); return RDTrimAudio::ErrorInternal; } @@ -155,6 +156,7 @@ RDTrimAudio::ErrorCode RDTrimAudio::runTrim(const QString &username, //fprintf(stderr,"CURL Error: %s [%d]\n",curl_easy_strerror(curl_err), //curl_err); curl_easy_cleanup(curl); + curl_formfree(first); return RDTrimAudio::ErrorInternal; case CURLE_URL_MALFORMAT: @@ -162,10 +164,12 @@ RDTrimAudio::ErrorCode RDTrimAudio::runTrim(const QString &username, case CURLE_COULDNT_CONNECT: case 9: // CURLE_REMOTE_ACCESS_DENIED curl_easy_cleanup(curl); + curl_formfree(first); return RDTrimAudio::ErrorUrlInvalid; } curl_easy_getinfo(curl,CURLINFO_RESPONSE_CODE,&response_code); curl_easy_cleanup(curl); + curl_formfree(first); switch(response_code) { case 200: diff --git a/lib/rdupload.cpp b/lib/rdupload.cpp index bd6738c4..df85d56d 100644 --- a/lib/rdupload.cpp +++ b/lib/rdupload.cpp @@ -134,20 +134,20 @@ RDUpload::ErrorCode RDUpload::runUpload(const QString &username, // otherwise some versions of LibCurl will throw a 'bad/illegal format' // error. // - strncpy(url,conv_dst_url.toString(conv_dst_url.protocol().lower()=="http"), + strncpy(url,conv_dst_url.toString(conv_dst_url.protocol().lower()=="http").utf8(), 1024); curl_easy_setopt(curl,CURLOPT_URL,url); curl_easy_setopt(curl,CURLOPT_UPLOAD,1); curl_easy_setopt(curl,CURLOPT_READDATA,f); curl_easy_setopt(curl,CURLOPT_INFILESIZE,(long)conv_src_size); - strncpy(userpwd,(username+":"+password),256); + strncpy(userpwd,(username+":"+password).utf8(),256); curl_easy_setopt(curl,CURLOPT_USERPWD,userpwd); curl_easy_setopt(curl,CURLOPT_TIMEOUT,RD_CURL_TIMEOUT); curl_easy_setopt(curl,CURLOPT_PROGRESSFUNCTION,UploadProgressCallback); curl_easy_setopt(curl,CURLOPT_PROGRESSDATA,this); curl_easy_setopt(curl,CURLOPT_NOPROGRESS,0); curl_easy_setopt(curl,CURLOPT_USERAGENT, - (const char *)rda->config()->userAgent()); + (const char *)rda->config()->userAgent().utf8()); if(log_debug) { curl_easy_setopt(curl,CURLOPT_VERBOSE,1); curl_easy_setopt(curl,CURLOPT_DEBUGFUNCTION,UploadErrorCallback);