COMMON: Undo changes to common/ptr.h, remove Common::ScopedPtrC

The deletePointer() method approach cannot work, as it is called
by the destructor of the base class.
A possible correct solution would be to enhance ScopedPtr with a
"deleter" object like SharedPtr. But this seems overkill as long as we
need it in only one place.

svn-id: r54057
This commit is contained in:
Max Horn 2010-11-04 00:49:12 +00:00
parent 44c6a90643
commit 99cf0e3936
2 changed files with 13 additions and 19 deletions

View File

@ -320,24 +320,30 @@ bool DLObject::load() {
return false;
}
Common::ScopedPtrC<Elf32_Shdr> shdr(loadSectionHeaders(&ehdr));
Elf32_Shdr *shdr = loadSectionHeaders(&ehdr);
if (!shdr)
return false;
_symtab_sect = loadSymbolTable(&ehdr, shdr);
if (_symtab_sect < 0)
if (_symtab_sect < 0) {
free(shdr);
return false;
}
if (!loadStringTable(shdr))
if (!loadStringTable(shdr)) {
free(shdr);
return false;
}
// Offset by our segment allocated address
// must use _segmentVMA here for multiple segments (MIPS)
_segmentOffset = ptrdiff_t(_segment) - _segmentVMA;
relocateSymbols(_segmentOffset);
if (!relocateRels(&ehdr, shdr))
if (!relocateRels(&ehdr, shdr)) {
free(shdr);
return false;
}
return true;
}

View File

@ -242,17 +242,15 @@ public:
*/
operator bool() const { return _pointer != 0; }
void deletePointer() { delete _pointer; }
~ScopedPtr() {
deletePointer();
delete _pointer;
}
/**
* Resets the pointer with the new value. Old object will be destroyed
*/
void reset(PointerType o = 0) {
deletePointer();
delete _pointer;
_pointer = o;
}
@ -275,20 +273,10 @@ public:
return r;
}
protected:
private:
PointerType _pointer;
};
template<typename T>
class ScopedPtrC : public ScopedPtr<T> {
public:
typedef T *PointerType;
explicit ScopedPtrC(PointerType o = 0) : ScopedPtr<T>(o) {}
void deletePointer() { free(ScopedPtr<T>::_pointer); }
};
} // End of namespace Common
#endif