Author: axeld Date: 2010-08-28 18:50:26 +0200 (Sat, 28 Aug 2010) New Revision: 38421 Changeset: http://dev.haiku-os.org/changeset/38421 Modified: haiku/trunk/src/add-ons/kernel/file_systems/udf/DString.cpp haiku/trunk/src/add-ons/kernel/file_systems/udf/DString.h Log: * Added missing destructor; fString was leaked. This fixes CIDs 1411-1413. * Minor cleanup. Modified: haiku/trunk/src/add-ons/kernel/file_systems/udf/DString.cpp =================================================================== --- haiku/trunk/src/add-ons/kernel/file_systems/udf/DString.cpp 2010-08-28 16:46:18 UTC (rev 38420) +++ haiku/trunk/src/add-ons/kernel/file_systems/udf/DString.cpp 2010-08-28 16:50:26 UTC (rev 38421) @@ -3,10 +3,12 @@ * Distributed under the terms of the MIT License. */ + #include "DString.h" #include <string.h> + /*! \brief Creates a useless, empty string object. */ DString::DString() : @@ -51,13 +53,19 @@ } +DString::~DString() +{ + delete[] fString; +} + + void DString::SetTo(const DString &ref) { _Clear(); if (ref.Length() > 0) { fString = new(nothrow) uint8[ref.Length()]; - if (fString) { + if (fString != NULL) { fLength = ref.Length(); memcpy(fString, ref.String(), fLength); } @@ -94,7 +102,7 @@ if (destLength < fieldLength - 1) memset(&fString[destLength], 0, fieldLength - 1 - destLength); // Write the string length to the last character in the field - fString[fieldLength - 1] = destLength; + fString[fieldLength - 1] = destLength; } else { // Empty strings are to contain all zeros memset(fString, 0, fieldLength); @@ -120,7 +128,7 @@ DString::_Clear() { DEBUG_INIT("DString"); - delete [] fString; + delete[] fString; fString = NULL; fLength = 0; } Modified: haiku/trunk/src/add-ons/kernel/file_systems/udf/DString.h =================================================================== --- haiku/trunk/src/add-ons/kernel/file_systems/udf/DString.h 2010-08-28 16:46:18 UTC (rev 38420) +++ haiku/trunk/src/add-ons/kernel/file_systems/udf/DString.h 2010-08-28 16:50:26 UTC (rev 38421) @@ -2,16 +2,17 @@ * Copyright 2003, Tyler Dauwalder, tyler@xxxxxxxxxxxxxx * Distributed under the terms of the MIT License. */ - #ifndef _D_STRING_H #define _D_STRING_H + #include "UdfDebug.h" #include "UdfString.h" #include <util/kernel_cpp.h> + /*! \brief Fixed-length d-string class that takes a UdfString as input and provides a properly formatted ECMA-167 d-string of the given field length as ouput. @@ -20,23 +21,28 @@ */ class DString { public: - DString(); - DString(const DString &ref); - DString(const UdfString &string, uint8 fieldLength); - DString(const char *utf8, uint8 fieldLength); + DString(); + DString(const DString &ref); + DString(const UdfString &string, + uint8 fieldLength); + DString(const char *utf8, uint8 fieldLength); + ~DString(); - uint8 Length() const { return fLength; } + uint8 Length() const { return fLength; } - void SetTo(const DString &ref); - void SetTo(const UdfString &string, uint8 fieldLength); - void SetTo(const char *utf8, uint8 fieldLength); + void SetTo(const DString &ref); + void SetTo(const UdfString &string, uint8 fieldLength); + void SetTo(const char *utf8, uint8 fieldLength); - const uint8* String() const { return fString; } + const uint8* String() const { return fString; } + private: - void _Clear(); + void _Clear(); - uint8 fLength; - uint8 *fString; +private: + uint8 fLength; + uint8 *fString; }; + #endif // _D_STRING_H