Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Unified Diff: src/FileSystemJsObject.cpp

Issue 10310030: Convert references to FileSystem & Co. into shared pointers (avoid use after free) (Closed)
Patch Set: Created April 18, 2013, 11:59 a.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: src/FileSystemJsObject.cpp
===================================================================
--- a/src/FileSystemJsObject.cpp
+++ b/src/FileSystemJsObject.cpp
@@ -20,17 +20,17 @@ namespace
IoThread(JsEngine& jsEngine, JsValuePtr callback)
: jsEngine(jsEngine), fileSystem(jsEngine.GetFileSystem()),
callback(callback)
{
}
protected:
JsEngine& jsEngine;
- FileSystem& fileSystem;
+ FileSystemPtr fileSystem;
JsValuePtr callback;
};
class ReadThread : public IoThread
{
public:
ReadThread(JsEngine& jsEngine, JsValuePtr callback,
const std::string& path)
@@ -39,17 +39,17 @@ namespace
}
void Run()
{
std::string content;
std::string error;
try
{
- std::tr1::shared_ptr<std::istream> stream = fileSystem.Read(path);
+ std::tr1::shared_ptr<std::istream> stream = fileSystem->Read(path);
content = Utils::Slurp(*stream);
}
catch (std::exception& e)
{
error = e.what();
}
catch (...)
{
@@ -81,17 +81,17 @@ namespace
void Run()
{
std::string error;
try
{
std::tr1::shared_ptr<std::ostream> stream(new std::stringstream);
*stream << content;
- fileSystem.Write(path, stream);
+ fileSystem->Write(path, stream);
}
catch (std::exception& e)
{
error = e.what();
}
catch (...)
{
error = "Unknown error while writing to " + path;
@@ -119,17 +119,17 @@ namespace
{
}
void Run()
{
std::string error;
try
{
- fileSystem.Move(fromPath, toPath);
+ fileSystem->Move(fromPath, toPath);
}
catch (std::exception& e)
{
error = e.what();
}
catch (...)
{
error = "Unknown error while moving " + fromPath + " to " + toPath;
@@ -157,17 +157,17 @@ namespace
{
}
void Run()
{
std::string error;
try
{
- fileSystem.Remove(path);
+ fileSystem->Remove(path);
}
catch (std::exception& e)
{
error = e.what();
}
catch (...)
{
error = "Unknown error while removing " + path;
@@ -195,17 +195,17 @@ namespace
}
void Run()
{
std::string error;
FileSystem::StatResult statResult;
try
{
- statResult = fileSystem.Stat(path);
+ statResult = fileSystem->Stat(path);
}
catch (std::exception& e)
{
error = e.what();
}
catch (...)
{
error = "Unknown error while calling stat on " + path;
« no previous file with comments | « src/DefaultWebRequestCurl.cpp ('k') | src/JsEngine.cpp » ('j') | src/JsEngine.cpp » ('J')

Powered by Google App Engine
This is Rietveld