Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

use a map instead of a vector for holding plugin handles - ensures th…

…at we don't attempt to access the wrong one if an earlier handle was removed. Thanks to ulion for finding the issue
  • Loading branch information...
commit de8789a5ec3cb6a7b82d7e304d8755a59dd0c20d 1 parent 2c1be2c
Jonathan Marshall authored
16 xbmc/filesystem/PluginDirectory.cpp
View
@@ -46,7 +46,8 @@ using namespace XFILE;
using namespace std;
using namespace ADDON;
-vector<CPluginDirectory *> CPluginDirectory::globalHandles;
+map<int, CPluginDirectory *> CPluginDirectory::globalHandles;
+int CPluginDirectory::handleCounter = 0;
CCriticalSection CPluginDirectory::m_handleLock;
CPluginDirectory::CPluginDirectory()
@@ -64,23 +65,24 @@ CPluginDirectory::~CPluginDirectory(void)
int CPluginDirectory::getNewHandle(CPluginDirectory *cp)
{
CSingleLock lock(m_handleLock);
- int handle = (int)globalHandles.size();
- globalHandles.push_back(cp);
+ int handle = ++handleCounter;
+ globalHandles[handle] = cp;
return handle;
}
void CPluginDirectory::removeHandle(int handle)
{
CSingleLock lock(m_handleLock);
- if (handle >= 0 && handle < (int)globalHandles.size())
- globalHandles.erase(globalHandles.begin() + handle);
+ if (!globalHandles.erase(handle))
+ CLog::Log(LOGWARNING, "Attempt to erase invalid handle %i", handle);
}
CPluginDirectory *CPluginDirectory::dirFromHandle(int handle)
{
CSingleLock lock(m_handleLock);
- if (handle >= 0 && handle < (int)globalHandles.size())
- return globalHandles[handle];
+ map<int, CPluginDirectory *>::iterator i = globalHandles.find(handle);
+ if (i != globalHandles.end())
+ return i->second;
CLog::Log(LOGWARNING, "Attempt to use invalid handle %i", handle);
return NULL;
}
5 xbmc/filesystem/PluginDirectory.h
View
@@ -25,7 +25,7 @@
#include "SortFileItem.h"
#include <string>
-#include <vector>
+#include <map>
#include "threads/CriticalSection.h"
#include "addons/IAddon.h"
#include "PlatformDefs.h"
@@ -68,11 +68,12 @@ class CPluginDirectory : public IDirectory
bool StartScript(const CStdString& strPath, bool retrievingDir);
bool WaitOnScriptResult(const CStdString &scriptPath, int scriptId, const CStdString &scriptName, bool retrievingDir);
- static std::vector<CPluginDirectory*> globalHandles;
+ static std::map<int,CPluginDirectory*> globalHandles;
static int getNewHandle(CPluginDirectory *cp);
static void removeHandle(int handle);
static CPluginDirectory *dirFromHandle(int handle);
static CCriticalSection m_handleLock;
+ static int handleCounter;
CFileItemList* m_listItems;
CFileItem* m_fileResult;
Please sign in to comment.
Something went wrong with that request. Please try again.