Mercurial > hg > audiodb
comparison insert.cpp @ 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 | 4dcb09f5fe85 |
children | 74824093c1c4 |
comparison
equal
deleted
inserted
replaced
261:8b7b1734716c | 262:34ce7f7a177d |
---|---|
201 | 201 |
202 if(!usingPower && (dbH->flags & O2_FLAG_POWER)) | 202 if(!usingPower && (dbH->flags & O2_FLAG_POWER)) |
203 error("Must use power with power-enabled database", dbName); | 203 error("Must use power with power-enabled database", dbName); |
204 | 204 |
205 unsigned totalVectors=0; | 205 unsigned totalVectors=0; |
206 char *thisKey = new char[MAXSTR]; | |
207 char *thisFile = new char[MAXSTR]; | 206 char *thisFile = new char[MAXSTR]; |
207 char *thisKey = 0; | |
208 if (key && (key != inFile)) { | |
209 thisKey = new char[MAXSTR]; | |
210 } | |
208 char *thisTimesFileName = new char[MAXSTR]; | 211 char *thisTimesFileName = new char[MAXSTR]; |
209 char *thisPowerFileName = new char[MAXSTR]; | 212 char *thisPowerFileName = new char[MAXSTR]; |
210 | 213 |
211 do{ | 214 do{ |
212 filesIn->getline(thisFile,MAXSTR); | 215 filesIn->getline(thisFile,MAXSTR); |
213 if(key && key!=inFile) | 216 if(key && key!=inFile) { |
214 keysIn->getline(thisKey,MAXSTR); | 217 keysIn->getline(thisKey,MAXSTR); |
215 else | 218 } else { |
216 thisKey = thisFile; | 219 thisKey = thisFile; |
217 if(usingTimes) | 220 } |
218 timesFile->getline(thisTimesFileName,MAXSTR); | 221 if(usingTimes) { |
219 if(usingPower) | 222 timesFile->getline(thisTimesFileName,MAXSTR); |
223 } | |
224 if(usingPower) { | |
220 powerFile->getline(thisPowerFileName, MAXSTR); | 225 powerFile->getline(thisPowerFileName, MAXSTR); |
226 } | |
221 | 227 |
222 if(filesIn->eof()) | 228 if(filesIn->eof()) { |
223 break; | 229 break; |
224 | 230 } |
225 initInputFile(thisFile); | 231 initInputFile(thisFile); |
226 | 232 |
227 if(!enough_per_file_space_free()) { | 233 if(!enough_per_file_space_free()) { |
228 error("batchinsert failed: no more room for metadata", thisFile); | 234 error("batchinsert failed: no more room for metadata", thisFile); |
229 } | 235 } |
314 munmap(indata,statbuf.st_size); | 320 munmap(indata,statbuf.st_size); |
315 close(infid); | 321 close(infid); |
316 } while(!filesIn->eof()); | 322 } while(!filesIn->eof()); |
317 | 323 |
318 VERB_LOG(0, "%s %s %u vectors %ju bytes.\n", COM_BATCHINSERT, dbName, totalVectors, (intmax_t) (totalVectors * dbH->dim * sizeof(double))); | 324 VERB_LOG(0, "%s %s %u vectors %ju bytes.\n", COM_BATCHINSERT, dbName, totalVectors, (intmax_t) (totalVectors * dbH->dim * sizeof(double))); |
319 | 325 |
326 delete [] thisPowerFileName; | |
327 if(key && (key != inFile)) { | |
328 delete [] thisKey; | |
329 } | |
330 delete [] thisFile; | |
331 delete [] thisTimesFileName; | |
332 | |
333 delete filesIn; | |
334 delete keysIn; | |
335 | |
320 // Report status | 336 // Report status |
321 status(dbName); | 337 status(dbName); |
322 } | 338 } |