Skip to content
Snippets Groups Projects
Commit 1b8ab7ef authored by Eugen Sawin's avatar Eugen Sawin
Browse files

Bug 1302516 - [1.2] Add mutex locking to ZipCollection zip vector access. r=glandium

parent e2e57730
No related branches found
No related tags found
No related merge requests found
......@@ -506,22 +506,6 @@ MappableSeekableZStream::munmap(void *addr, size_t length)
void
MappableSeekableZStream::finalize() { }
class AutoLock {
public:
AutoLock(pthread_mutex_t *mutex): mutex(mutex)
{
if (pthread_mutex_lock(mutex))
MOZ_CRASH("pthread_mutex_lock failed");
}
~AutoLock()
{
if (pthread_mutex_unlock(mutex))
MOZ_CRASH("pthread_mutex_unlock failed");
}
private:
pthread_mutex_t *mutex;
};
bool
MappableSeekableZStream::ensure(const void *addr)
{
......
......@@ -5,7 +5,6 @@
#ifndef Mappable_h
#define Mappable_h
#include <pthread.h>
#include "Zip.h"
#include "SeekableZStream.h"
#include "mozilla/RefPtr.h"
......
......@@ -5,6 +5,7 @@
#ifndef Utils_h
#define Utils_h
#include <pthread.h>
#include <stdint.h>
#include <stddef.h>
#include <sys/mman.h>
......@@ -597,5 +598,21 @@ void *FunctionPtr(T func)
return f.ptr;
}
class AutoLock {
public:
AutoLock(pthread_mutex_t *mutex): mutex(mutex)
{
if (pthread_mutex_lock(mutex))
MOZ_CRASH("pthread_mutex_lock failed");
}
~AutoLock()
{
if (pthread_mutex_unlock(mutex))
MOZ_CRASH("pthread_mutex_unlock failed");
}
private:
pthread_mutex_t *mutex;
};
#endif /* Utils_h */
......@@ -183,15 +183,20 @@ Zip::GetFirstEntry() const
ZipCollection ZipCollection::Singleton;
static pthread_mutex_t sZipCollectionMutex = PTHREAD_MUTEX_INITIALIZER;
already_AddRefed<Zip>
ZipCollection::GetZip(const char *path)
{
/* Search the list of Zips we already have for a match */
for (std::vector<Zip *>::iterator it = Singleton.zips.begin();
it < Singleton.zips.end(); ++it) {
if ((*it)->GetName() && (strcmp((*it)->GetName(), path) == 0)) {
RefPtr<Zip> zip = *it;
return zip.forget();
{
AutoLock lock(&sZipCollectionMutex);
/* Search the list of Zips we already have for a match */
for (std::vector<Zip *>::iterator it = Singleton.zips.begin();
it < Singleton.zips.end(); ++it) {
if ((*it)->GetName() && (strcmp((*it)->GetName(), path) == 0)) {
RefPtr<Zip> zip = *it;
return zip.forget();
}
}
}
return Zip::Create(path);
......@@ -200,12 +205,15 @@ ZipCollection::GetZip(const char *path)
void
ZipCollection::Register(Zip *zip)
{
AutoLock lock(&sZipCollectionMutex);
DEBUG_LOG("ZipCollection::Register(\"%s\")", zip->GetName());
Singleton.zips.push_back(zip);
}
void
ZipCollection::Forget(Zip *zip)
{
AutoLock lock(&sZipCollectionMutex);
DEBUG_LOG("ZipCollection::Forget(\"%s\")", zip->GetName());
std::vector<Zip *>::iterator it = std::find(Singleton.zips.begin(),
Singleton.zips.end(), zip);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment