Skip to content

Commit

Permalink
Fix memory leak of AddressSpace::patcher_ (#795)
Browse files Browse the repository at this point in the history
This was originally part of #317.
This is an API-breaking change since AddressSpace is exported through
the BPatch interface.
  • Loading branch information
hainest committed Oct 16, 2020
1 parent 7270afc commit 5250435
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 9 deletions.
3 changes: 1 addition & 2 deletions dyninstAPI/src/addressSpace.C
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,7 @@ AddressSpace::AddressSpace () :
memEmulator_(NULL),
emulateMem_(false),
emulatePC_(false),
delayRelocation_(false),
patcher_(NULL)
delayRelocation_(false)
{
#if 0
// Disabled for now; used by defensive mode
Expand Down
6 changes: 3 additions & 3 deletions dyninstAPI/src/addressSpace.h
Original file line number Diff line number Diff line change
Expand Up @@ -567,14 +567,14 @@ class AddressSpace : public InstructionSource {
public:
Dyninst::PatchAPI::PatchMgrPtr mgr() const { assert(mgr_); return mgr_; }
void setMgr(Dyninst::PatchAPI::PatchMgrPtr m) { mgr_ = m; }
void setPatcher(Dyninst::PatchAPI::Patcher* p) { patcher_ = p; }
void setPatcher(Dyninst::PatchAPI::Patcher::Ptr p) { patcher_ = p; }
void initPatchAPI();
void addMappedObject(mapped_object* obj);
Dyninst::PatchAPI::Patcher* patcher() { return patcher_; }
Dyninst::PatchAPI::Patcher::Ptr patcher() { return patcher_; }
static bool patch(AddressSpace*);
protected:
Dyninst::PatchAPI::PatchMgrPtr mgr_;
Dyninst::PatchAPI::Patcher* patcher_;
Dyninst::PatchAPI::Patcher::Ptr patcher_;
};


Expand Down
2 changes: 1 addition & 1 deletion dyninstAPI/src/binaryEdit.C
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ BinaryEdit::~BinaryEdit()

BinaryEdit *BinaryEdit::openFile(const std::string &file,
PatchMgrPtr mgr,
Dyninst::PatchAPI::Patcher *patch,
Dyninst::PatchAPI::Patcher::Ptr patch,
const std::string &member) {
if (!OS::executableExists(file)) {
startup_printf("%s[%d]: failed to read file %s\n", FILE__, __LINE__, file.c_str());
Expand Down
2 changes: 1 addition & 1 deletion dyninstAPI/src/binaryEdit.h
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ class BinaryEdit : public AddressSpace {
// And the "open" factory method.
static BinaryEdit *openFile(const std::string &file,
Dyninst::PatchAPI::PatchMgrPtr mgr = Dyninst::PatchAPI::PatchMgrPtr(),
Dyninst::PatchAPI::Patcher *patch = NULL,
Dyninst::PatchAPI::Patcher::Ptr patch = Dyninst::PatchAPI::Patcher::Ptr(),
const std::string &member = "");

bool writeFile(const std::string &newFileName);
Expand Down
5 changes: 3 additions & 2 deletions patchAPI/h/Command.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,9 @@ class PATCHAPI_EXPORT BatchCommand : public Command {

class PATCHAPI_EXPORT Patcher : public BatchCommand {
public:
static Patcher* create(Dyninst::PatchAPI::PatchMgrPtr mgr) {
return new Patcher(mgr);
using Ptr = boost::shared_ptr<Patcher>;
static Ptr create(Dyninst::PatchAPI::PatchMgrPtr mgr) {
return boost::make_shared<Patcher>(mgr);
}
Patcher(Dyninst::PatchAPI::PatchMgrPtr mgr) : mgr_(mgr) {}
virtual ~Patcher() {}
Expand Down

0 comments on commit 5250435

Please sign in to comment.