DiskProbe: fix crash when trying to edit a package directory

/system and /home/config would crash diskprobe because DataEditor would
be left in an incompletely initialized state.

Also fix a memory leak: fAttribute was never freed, but is allocated with
strdup.

Fixes #10428.
This commit is contained in:
Adrien Destugues
2014-11-20 14:07:11 +01:00
parent 1581d4ef08
commit 23b89f011f
+11 -5
View File
@@ -369,12 +369,14 @@ ReplaceChange::GetRange(off_t /*fileSize*/, off_t &_offset, off_t &_size)
DataEditor::DataEditor()
: BLocker("data view")
, fAttribute(NULL)
{
}
DataEditor::DataEditor(entry_ref &ref, const char *attribute)
: BLocker("data view")
, fAttribute(NULL)
{
SetTo(ref, attribute);
}
@@ -382,6 +384,7 @@ DataEditor::DataEditor(entry_ref &ref, const char *attribute)
DataEditor::DataEditor(BEntry &entry, const char *attribute)
: BLocker("data view")
, fAttribute(NULL)
{
SetTo(entry, attribute);
}
@@ -389,12 +392,14 @@ DataEditor::DataEditor(BEntry &entry, const char *attribute)
DataEditor::DataEditor(const DataEditor &editor)
: BLocker("data view")
, fAttribute(NULL)
{
}
DataEditor::~DataEditor()
{
free((void*)fAttribute);
}
@@ -425,6 +430,12 @@ DataEditor::SetTo(BEntry &entry, const char *attribute)
fViewOffset = 0;
fRealViewSize = fViewSize = fBlockSize = 512;
free((void*)fAttribute);
if (attribute != NULL)
fAttribute = strdup(attribute);
else
fAttribute = NULL;
struct stat stat;
status_t status = entry.GetStat(&stat);
if (status < B_OK)
@@ -468,11 +479,6 @@ DataEditor::SetTo(BEntry &entry, const char *attribute)
entry.GetRef(&fRef);
fIsDevice = S_ISBLK(stat.st_mode) || S_ISCHR(stat.st_mode);
if (attribute != NULL)
fAttribute = strdup(attribute);
else
fAttribute = NULL;
if (IsAttribute()) {
BNode node(&fAttributeRef);
attr_info info;