cleanup for valgrind.

This commit is contained in:
barant 2024-12-23 13:00:22 -08:00
parent 0ebe8eaf5b
commit cfd996fe5a
2 changed files with 7 additions and 6 deletions

2
File.h
View File

@ -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();

View File

@ -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;