cleanup for valgrind.

This commit is contained in:
barant 2024-12-23 11:15:53 -08:00
parent e5bfd7a840
commit 0ebe8eaf5b
3 changed files with 15 additions and 9 deletions

View File

@ -34,7 +34,7 @@ namespace coreutils {
File::~File() { File::~File() {
close(fd); close(fd);
setBufferSize(0); free(buffer);
} }
void File::setBufferSize(size_t size) { void File::setBufferSize(size_t size) {

View File

@ -66,8 +66,10 @@ namespace coreutils {
} }
ZString::~ZString() { ZString::~ZString() {
if(cdata != NULL) if(cdata != NULL) {
free(cdata); std::cout << "********" << cdata << "********" << strlen(cdata) << std::endl;
free(cdata);
}
} }
bool ZString::operator<(const ZString &valuex) const { bool ZString::operator<(const ZString &valuex) const {
@ -443,8 +445,12 @@ namespace coreutils {
} }
int ZString::skipWhitespace() { int ZString::skipWhitespace() {
int len = strspn(cursor, " \n\t"); char *end = data + length;
cursor += len; int len = 0;
while((cursor < end) && ((*cursor == ' ') || (*cursor == '\n') || (*cursor == '\t'))) {
++cursor;
++len;
}
return len; return len;
} }

View File

@ -84,7 +84,7 @@ namespace coreutils {
/// Destructor for the ZString. /// Destructor for the ZString.
/// ///
~ZString(); virtual ~ZString();
/// ///
/// A friend method used to write the value of the ZString /// A friend method used to write the value of the ZString
@ -454,9 +454,9 @@ namespace coreutils {
void moveBackToLineStart(); void moveBackToLineStart();
protected: protected:
char *data; char *data = NULL;
char *cursor; char *cursor = NULL;
size_t length; size_t length = 0;
char *cdata = NULL; char *cdata = NULL;
std::vector<ZString> list; std::vector<ZString> list;