Skip to content
This repository
Browse code

[nfs] - fix possible crash due to a race condition between context ti…

…meout and filehandle keepalive. This is related to / addition fix for #13505
  • Loading branch information...
commit 2896704f85c29b77533f1c653d3f63e1debcfcc0 1 parent ae04d99
Memphiz authored November 25, 2012
11  xbmc/filesystem/NFSFile.cpp
@@ -140,7 +140,7 @@ void CNfsConnection::destroyOpenContexts()
140 140
   m_openContextMap.clear();
141 141
 }
142 142
 
143  
-struct nfs_context *CNfsConnection::getContextFromMap(const CStdString &exportname)
  143
+struct nfs_context *CNfsConnection::getContextFromMap(const CStdString &exportname, bool forceCacheHit/* = false*/)
144 144
 {
145 145
   struct nfs_context *pRet = NULL;
146 146
   CSingleLock lock(openContextLock);
@@ -150,9 +150,9 @@ struct nfs_context *CNfsConnection::getContextFromMap(const CStdString &exportna
150 150
   {
151 151
     //check if context has timed out already
152 152
     uint64_t now = XbmcThreads::SystemClockMillis();
153  
-    if((now - it->second.lastAccessedTime) < CONTEXT_TIMEOUT)
  153
+    if((now - it->second.lastAccessedTime) < CONTEXT_TIMEOUT || forceCacheHit)
154 154
     {
155  
-      //its not timedout yet
  155
+      //its not timedout yet or caller wants the cached entry regardless of timeout
156 156
       //refresh access time of that
157 157
       //context and return it
158 158
       CLog::Log(LOGDEBUG, "NFS: Refreshing context for %s, old: %"PRId64", new: %"PRId64, exportname.c_str(), it->second.lastAccessedTime, now);
@@ -383,7 +383,10 @@ void CNfsConnection::keepAlive(std::string _exportPath, struct nfsfh  *_pFileHan
383 383
   uint64_t offset = 0;
384 384
   char buffer[32];
385 385
   // this also refreshs the last accessed time for the context
386  
-  struct nfs_context *pContext = getContextFromMap(_exportPath);
  386
+  // true forces a cachehit regardless the context is timedout
  387
+  // on this call we are sure its not timedout even if the last accessed
  388
+  // time suggests it.
  389
+  struct nfs_context *pContext = getContextFromMap(_exportPath, true);
387 390
   
388 391
   if (!pContext)// this should normally never happen - paranoia
389 392
     pContext = m_pNfsContext;
2  xbmc/filesystem/NFSFile.h
@@ -114,7 +114,7 @@ class CNfsConnection : public CCriticalSection
114 114
   CCriticalSection openContextLock;
115 115
  
116 116
   void clearMembers();
117  
-  struct nfs_context *getContextFromMap(const CStdString &exportname);
  117
+  struct nfs_context *getContextFromMap(const CStdString &exportname, bool forceCacheHit = false);
118 118
   int  getContextForExport(const CStdString &exportname);//get context for given export and add to open contexts map - sets m_pNfsContext (my return a already mounted cached context)
119 119
   void destroyOpenContexts();
120 120
   void resolveHost(const CURL &url);//resolve hostname by dnslookup

0 notes on commit 2896704

Please sign in to comment.
Something went wrong with that request. Please try again.