From cfd996fe5a1cd5591d3b9bb12128b1d8dcde8fb1 Mon Sep 17 00:00:00 2001 From: barant Date: Mon, 23 Dec 2024 13:00:22 -0800 Subject: [PATCH] cleanup for valgrind. --- File.h | 2 +- ZString.cpp | 11 ++++++----- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/File.h b/File.h index fe8e471..86937c9 100644 --- a/File.h +++ b/File.h @@ -17,7 +17,7 @@ namespace coreutils { public: File(ZString fileName, int mode = O_RDONLY, int authority = 0664); - ~File(); + virtual ~File(); void setBufferSize(size_t size); int read(); int readLine(); diff --git a/ZString.cpp b/ZString.cpp index 4efef4c..acabe6e 100644 --- a/ZString.cpp +++ b/ZString.cpp @@ -66,10 +66,8 @@ namespace coreutils { } ZString::~ZString() { - if(cdata != NULL) { - std::cout << "********" << cdata << "********" << strlen(cdata) << std::endl; - free(cdata); - } + if(cdata != NULL) + free(cdata); } bool ZString::operator<(const ZString &valuex) const { @@ -234,7 +232,10 @@ namespace coreutils { } char* ZString::c_str() { - cdata = (char *)malloc(length + 1); + if(cdata == NULL) + cdata = (char *)malloc(length + 1); + else + cdata = (char *)realloc(cdata, length + 1); strncpy(cdata, data, length); cdata[length] = '\0'; return cdata;