* Added missing destructor; fString was leaked. This fixes CIDs 1411-1413.

* Minor cleanup.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@38421 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Axel Dörfler
2010-08-28 16:50:26 +00:00
parent 44260788fe
commit 6195b696db
2 changed files with 30 additions and 16 deletions
@@ -3,10 +3,12 @@
* Distributed under the terms of the MIT License. * Distributed under the terms of the MIT License.
*/ */
#include "DString.h" #include "DString.h"
#include <string.h> #include <string.h>
/*! \brief Creates a useless, empty string object. */ /*! \brief Creates a useless, empty string object. */
DString::DString() DString::DString()
: :
@@ -51,13 +53,19 @@ DString::DString(const char *utf8, uint8 fieldLength)
} }
DString::~DString()
{
delete[] fString;
}
void void
DString::SetTo(const DString &ref) DString::SetTo(const DString &ref)
{ {
_Clear(); _Clear();
if (ref.Length() > 0) { if (ref.Length() > 0) {
fString = new(nothrow) uint8[ref.Length()]; fString = new(nothrow) uint8[ref.Length()];
if (fString) { if (fString != NULL) {
fLength = ref.Length(); fLength = ref.Length();
memcpy(fString, ref.String(), fLength); memcpy(fString, ref.String(), fLength);
} }
@@ -120,7 +128,7 @@ void
DString::_Clear() DString::_Clear()
{ {
DEBUG_INIT("DString"); DEBUG_INIT("DString");
delete [] fString; delete[] fString;
fString = NULL; fString = NULL;
fLength = 0; fLength = 0;
} }
+19 -13
View File
@@ -2,16 +2,17 @@
* Copyright 2003, Tyler Dauwalder, [email protected]. * Copyright 2003, Tyler Dauwalder, [email protected].
* Distributed under the terms of the MIT License. * Distributed under the terms of the MIT License.
*/ */
#ifndef _D_STRING_H #ifndef _D_STRING_H
#define _D_STRING_H #define _D_STRING_H
#include "UdfDebug.h" #include "UdfDebug.h"
#include "UdfString.h" #include "UdfString.h"
#include <util/kernel_cpp.h> #include <util/kernel_cpp.h>
/*! \brief Fixed-length d-string class that takes a UdfString as input /*! \brief Fixed-length d-string class that takes a UdfString as input
and provides a properly formatted ECMA-167 d-string of the given and provides a properly formatted ECMA-167 d-string of the given
field length as ouput. field length as ouput.
@@ -20,23 +21,28 @@
*/ */
class DString { class DString {
public: public:
DString(); DString();
DString(const DString &ref); DString(const DString &ref);
DString(const UdfString &string, uint8 fieldLength); DString(const UdfString &string,
DString(const char *utf8, uint8 fieldLength); 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 DString &ref);
void SetTo(const UdfString &string, uint8 fieldLength); void SetTo(const UdfString &string, uint8 fieldLength);
void SetTo(const char *utf8, uint8 fieldLength); void SetTo(const char *utf8, uint8 fieldLength);
const uint8* String() const { return fString; }
const uint8* String() const { return fString; }
private: private:
void _Clear(); void _Clear();
uint8 fLength; private:
uint8 *fString; uint8 fLength;
uint8 *fString;
}; };
#endif // _D_STRING_H #endif // _D_STRING_H