Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorvng <viktor.govako@gmail.com>2012-11-06 20:47:49 +0400
committerAlex Zolotarev <alex@maps.me>2015-09-23 01:46:39 +0300
commitb9bc599a21b49cf83eb6a31eaa450adf5c2e930e (patch)
tree8714d5795782680f0c36758e7222b8dd1f5324f5 /platform
parent051df2870ed75c71ed3eaf153e8c1d7947079f10 (diff)
Safe delete of HttpThreads in destructor of HttpRequest (remove from list).
Diffstat (limited to 'platform')
-rw-r--r--platform/http_request.cpp44
1 files changed, 32 insertions, 12 deletions
diff --git a/platform/http_request.cpp b/platform/http_request.cpp
index 4b1924a136..82f650c308 100644
--- a/platform/http_request.cpp
+++ b/platform/http_request.cpp
@@ -111,7 +111,8 @@ public:
class FileHttpRequest : public HttpRequest, public IHttpThreadCallback
{
ChunksDownloadStrategy m_strategy;
- typedef list<pair<HttpThread *, int64_t> > ThreadsContainerT;
+ typedef pair<HttpThread *, int64_t> ThreadHandleT;
+ typedef list<ThreadHandleT> ThreadsContainerT;
ThreadsContainerT m_threads;
string m_filePath;
@@ -134,16 +135,29 @@ class FileHttpRequest : public HttpRequest, public IHttpThreadCallback
return result;
}
+ class ThreadByPos
+ {
+ int64_t m_pos;
+ public:
+ ThreadByPos(int64_t pos) : m_pos(pos) {}
+ inline bool operator() (ThreadHandleT const & p) const
+ {
+ return (p.second == m_pos);
+ }
+ };
+
void RemoveHttpThreadByKey(int64_t begRange)
{
- for (ThreadsContainerT::iterator it = m_threads.begin(); it != m_threads.end(); ++it)
- if (it->second == begRange)
- {
- DeleteNativeHttpThread(it->first);
- m_threads.erase(it);
- return;
- }
- ASSERT ( false, ("Tried to remove invalid thread?") );
+ ThreadsContainerT::iterator it = find_if(m_threads.begin(), m_threads.end(),
+ ThreadByPos(begRange));
+ if (it != m_threads.end())
+ {
+ HttpThread * p = it->first;
+ m_threads.erase(it);
+ DeleteNativeHttpThread(p);
+ }
+ else
+ LOG(LERROR, ("Tried to remove invalid thread for position", begRange));
}
virtual bool OnWrite(int64_t offset, void const * buffer, size_t size)
@@ -297,13 +311,19 @@ public:
DisableBackupForFile(filePath + DOWNLOADING_FILE_EXTENSION);
#endif
- StartThreads();
+ (void)StartThreads();
}
virtual ~FileHttpRequest()
{
- for (ThreadsContainerT::iterator it = m_threads.begin(); it != m_threads.end(); ++it)
- DeleteNativeHttpThread(it->first);
+ // Do safe delete with removing from list in case if DeleteNativeHttpThread
+ // can produce final notifications to this->OnFinish().
+ while (!m_threads.empty())
+ {
+ HttpThread * p = m_threads.back().first;
+ m_threads.pop_back();
+ DeleteNativeHttpThread(p);
+ }
if (m_status == EInProgress)
{