[haiku-commits] haiku: hrev48348 - src/apps/diskprobe

  • From: pulkomandy@xxxxxxxxxxxxx
  • To: haiku-commits@xxxxxxxxxxxxx
  • Date: Thu, 20 Nov 2014 14:08:40 +0100 (CET)

hrev48348 adds 1 changeset to branch 'master'
old head: 1581d4ef08b8f6d1a6b26ff84b5c2ca2ea779b99
new head: 23b89f011f1399beec949c55f49183a81170c526
overview: http://cgit.haiku-os.org/haiku/log/?qt=range&q=23b89f0+%5E1581d4e

----------------------------------------------------------------------------

23b89f0: 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.

                                 [ Adrien Destugues <pulkomandy@xxxxxxxxx> ]

----------------------------------------------------------------------------

Revision:    hrev48348
Commit:      23b89f011f1399beec949c55f49183a81170c526
URL:         http://cgit.haiku-os.org/haiku/commit/?id=23b89f0
Author:      Adrien Destugues <pulkomandy@xxxxxxxxx>
Date:        Thu Nov 20 13:07:11 2014 UTC

Ticket:      https://dev.haiku-os.org/ticket/10428

----------------------------------------------------------------------------

1 file changed, 11 insertions(+), 5 deletions(-)
src/apps/diskprobe/DataEditor.cpp | 16 +++++++++++-----

----------------------------------------------------------------------------

diff --git a/src/apps/diskprobe/DataEditor.cpp 
b/src/apps/diskprobe/DataEditor.cpp
index 97539ad..59f4641 100644
--- a/src/apps/diskprobe/DataEditor.cpp
+++ b/src/apps/diskprobe/DataEditor.cpp
@@ -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;


Other related posts: