Skip to content
Snippets Groups Projects
Unverified Commit 7486e60d authored by Richard Cordovano's avatar Richard Cordovano Committed by GitHub
Browse files

Merge pull request #1665 from jkho/5589-memory-leak-rejistry++

5589 Fix memory leaks in Rejistry++
parents 82d254b3 971a9490
No related branches found
No related tags found
No related merge requests found
...@@ -48,6 +48,10 @@ namespace Rejistry { ...@@ -48,6 +48,10 @@ namespace Rejistry {
*/ */
virtual REGFHeader * getHeader() const = 0; virtual REGFHeader * getHeader() const = 0;
/**
* Virtual destructor to prevent memory leak
*/
virtual ~RegistryHive() {}
}; };
}; };
......
...@@ -47,7 +47,10 @@ namespace Rejistry { ...@@ -47,7 +47,10 @@ namespace Rejistry {
} }
RegistryKey * RegistryHiveBuffer::getRoot() const { RegistryKey * RegistryHiveBuffer::getRoot() const {
return new RegistryKey(getHeader()->getRootNKRecord()); REGFHeader *header = getHeader();
Rejistry::NKRecord *nkRecord = header->getRootNKRecord();
delete header;
return new RegistryKey(nkRecord);
} }
REGFHeader * RegistryHiveBuffer::getHeader() const { REGFHeader * RegistryHiveBuffer::getHeader() const {
......
...@@ -74,19 +74,34 @@ namespace Rejistry { ...@@ -74,19 +74,34 @@ namespace Rejistry {
*/ */
RegistryKey::RegistryKeyPtrList RegistryKey::getSubkeyList() const { RegistryKey::RegistryKeyPtrList RegistryKey::getSubkeyList() const {
std::vector<RegistryKey *> subkeys; std::vector<RegistryKey *> subkeys;
NKRecord::NKRecordPtrList nkRecordList = _nk->getSubkeyList()->getSubkeys(); SubkeyListRecord::SubkeyListRecordPtr subkeyListRecordPtr = _nk->getSubkeyList();
NKRecord::NKRecordPtrList nkRecordList = subkeyListRecordPtr->getSubkeys();
NKRecord::NKRecordPtrList::iterator it; NKRecord::NKRecordPtrList::iterator it;
for (it = nkRecordList.begin(); it != nkRecordList.end(); ++it) { for (it = nkRecordList.begin(); it != nkRecordList.end(); ++it) {
subkeys.push_back(new RegistryKey(*it)); subkeys.push_back(new RegistryKey(*it));
} }
delete subkeyListRecordPtr;
return subkeys; return subkeys;
} }
size_t RegistryKey::getSubkeyListSize() const {
std::vector<RegistryKey *> subkeys;
SubkeyListRecord::SubkeyListRecordPtr subkeyListRecordPtr = _nk->getSubkeyList();
NKRecord::NKRecordPtrList nkRecordList = subkeyListRecordPtr->getSubkeys();
delete subkeyListRecordPtr;
return nkRecordList.size();
}
/** /**
* Caller is responsible for freeing returned key * Caller is responsible for freeing returned key
*/ */
RegistryKey::RegistryKeyPtr RegistryKey::getSubkey(const std::wstring& name) const { RegistryKey::RegistryKeyPtr RegistryKey::getSubkey(const std::wstring& name) const {
return new RegistryKey(_nk->getSubkeyList()->getSubkey(name)); SubkeyListRecord::SubkeyListRecordPtr subkeyListRecordPtr = _nk->getSubkeyList();
Rejistry::NKRecord *nkRecord = subkeyListRecordPtr->getSubkey(name);
delete subkeyListRecordPtr;
return new RegistryKey(nkRecord);
} }
/** /**
...@@ -102,10 +117,21 @@ namespace Rejistry { ...@@ -102,10 +117,21 @@ namespace Rejistry {
return values; return values;
} }
size_t RegistryKey::getValueListSize() const {
Rejistry::ValueListRecord *valueListRecord = _nk->getValueList();
size_t size = valueListRecord->getValuesSize();
delete valueListRecord;
return size;
}
/** /**
* Caller is responsible for freeing returned value * Caller is responsible for freeing returned value
*/ */
RegistryValue::RegistryValuePtr RegistryKey::getValue(const std::wstring& name) const { RegistryValue::RegistryValuePtr RegistryKey::getValue(const std::wstring& name) const {
return new RegistryValue(_nk->getValueList()->getValue(name)); Rejistry::ValueListRecord *valueListRecord = _nk->getValueList();
Rejistry::VKRecord *vkRecord = valueListRecord->getValue(name);
delete valueListRecord;
return new RegistryValue(vkRecord);
} }
}; };
...@@ -73,6 +73,13 @@ namespace Rejistry { ...@@ -73,6 +73,13 @@ namespace Rejistry {
*/ */
RegistryKeyPtrList getSubkeyList() const; RegistryKeyPtrList getSubkeyList() const;
/**
* Get number of subkeys for the current registry key.
* @returns number of subkeys.
* @throws RegistryParseException on error.
*/
size_t getSubkeyListSize() const;
/** /**
* Get the subkey with the given name. * Get the subkey with the given name.
* @param name ASCII name of the subkey of retrieve. * @param name ASCII name of the subkey of retrieve.
...@@ -88,6 +95,13 @@ namespace Rejistry { ...@@ -88,6 +95,13 @@ namespace Rejistry {
*/ */
RegistryValue::RegistryValuePtrList getValueList() const; RegistryValue::RegistryValuePtrList getValueList() const;
/**
* Get number of values for the current key.
* @returns Number of values.
* @throws RegistryParseException on error.
*/
size_t getValueListSize() const;
/** /**
* Get the value for the given name. * Get the value for the given name.
* @param name ASCII name of the value to retrieve. * @param name ASCII name of the value to retrieve.
......
...@@ -68,6 +68,11 @@ namespace Rejistry { ...@@ -68,6 +68,11 @@ namespace Rejistry {
_type = type; _type = type;
} }
~ValueData() {
if (_buf)
delete _buf;
}
VALUE_TYPES getValueType() const { return _type; }; VALUE_TYPES getValueType() const { return _type; };
/** /**
......
...@@ -61,6 +61,11 @@ namespace Rejistry { ...@@ -61,6 +61,11 @@ namespace Rejistry {
*/ */
VKRecord::VKRecordPtr getValue(const std::wstring& name) const; VKRecord::VKRecordPtr getValue(const std::wstring& name) const;
/**
* @returns The ValueListRecord size
*/
size_t getValuesSize() const { return _numValues; }
private: private:
static const uint16_t VALUE_LIST_OFFSET = 0x00; static const uint16_t VALUE_LIST_OFFSET = 0x00;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment