Mercurial > hg > audiodb
changeset 262:34ce7f7a177d
Remove, I think, memory leaks from audioDB::batchinsert().
Add paired delete / delete[]s, with the catch that we need to handle the
key file a bit carefully.
author | mas01cr |
---|---|
date | Mon, 19 May 2008 16:25:12 +0000 |
parents | 8b7b1734716c |
children | 210b2f661b88 |
files | insert.cpp |
diffstat | 1 files changed, 24 insertions(+), 8 deletions(-) [+] |
line wrap: on
line diff
--- a/insert.cpp Mon May 19 16:05:39 2008 +0000 +++ b/insert.cpp Mon May 19 16:25:12 2008 +0000 @@ -203,25 +203,31 @@ error("Must use power with power-enabled database", dbName); unsigned totalVectors=0; - char *thisKey = new char[MAXSTR]; char *thisFile = new char[MAXSTR]; + char *thisKey = 0; + if (key && (key != inFile)) { + thisKey = new char[MAXSTR]; + } char *thisTimesFileName = new char[MAXSTR]; char *thisPowerFileName = new char[MAXSTR]; do{ filesIn->getline(thisFile,MAXSTR); - if(key && key!=inFile) + if(key && key!=inFile) { keysIn->getline(thisKey,MAXSTR); - else + } else { thisKey = thisFile; - if(usingTimes) - timesFile->getline(thisTimesFileName,MAXSTR); - if(usingPower) + } + if(usingTimes) { + timesFile->getline(thisTimesFileName,MAXSTR); + } + if(usingPower) { powerFile->getline(thisPowerFileName, MAXSTR); + } - if(filesIn->eof()) + if(filesIn->eof()) { break; - + } initInputFile(thisFile); if(!enough_per_file_space_free()) { @@ -316,7 +322,17 @@ } while(!filesIn->eof()); VERB_LOG(0, "%s %s %u vectors %ju bytes.\n", COM_BATCHINSERT, dbName, totalVectors, (intmax_t) (totalVectors * dbH->dim * sizeof(double))); + + delete [] thisPowerFileName; + if(key && (key != inFile)) { + delete [] thisKey; + } + delete [] thisFile; + delete [] thisTimesFileName; + delete filesIn; + delete keysIn; + // Report status status(dbName); }