comparison lshlib.cpp @ 481:cead91ecf9a2 memory-leaks

added file descriptor close() in lshlib.cpp
author mas01mc
date Sat, 10 Jan 2009 13:23:01 +0000
parents 2d5c3f8e8c22
children bf54b8fa7d89
comparison
equal deleted inserted replaced
480:d7c23fcc8e2a 481:cead91ecf9a2
470 indexName(0), 470 indexName(0),
471 lshHeader(0), 471 lshHeader(0),
472 calling_instance(0), 472 calling_instance(0),
473 add_point_callback(0) 473 add_point_callback(0)
474 { 474 {
475 FILE* dbFile = 0;
475 int dbfid = unserialize_lsh_header(filename); 476 int dbfid = unserialize_lsh_header(filename);
476 indexName = new char[O2_INDEX_MAXSTR]; 477 indexName = new char[O2_INDEX_MAXSTR];
477 strncpy(indexName, filename, O2_INDEX_MAXSTR); // COPY THE CONTENTS TO THE NEW POINTER 478 strncpy(indexName, filename, O2_INDEX_MAXSTR); // COPY THE CONTENTS TO THE NEW POINTER
478 H::initialize_lsh_functions(); // Base-class data-structure initialization 479 H::initialize_lsh_functions(); // Base-class data-structure initialization
479 unserialize_lsh_functions(dbfid); // populate with on-disk hashfunction values 480 unserialize_lsh_functions(dbfid); // populate with on-disk hashfunction values
483 unserialize_lsh_hashtables_format1(dbfid); 484 unserialize_lsh_hashtables_format1(dbfid);
484 } 485 }
485 486
486 // Format2 always needs unserializing 487 // Format2 always needs unserializing
487 if(lshHeader->flags&O2_SERIAL_FILEFORMAT2 && lshInCoreFlag){ 488 if(lshHeader->flags&O2_SERIAL_FILEFORMAT2 && lshInCoreFlag){
488 FILE* dbFile = fdopen(dbfid, "rb"); 489 dbFile = fdopen(dbfid, "rb");
489 if(!dbFile) 490 if(!dbFile)
490 error("Cannot open LSH file for reading", filename); 491 error("Cannot open LSH file for reading", filename);
491 unserialize_lsh_hashtables_format2(dbFile); 492 unserialize_lsh_hashtables_format2(dbFile);
492 } 493 }
493 serial_close(dbfid); 494 serial_close(dbfid);
495 if(dbFile){
496 fclose(dbFile);
497 dbFile = 0;
498 }
494 } 499 }
495 500
496 G::~G(){ 501 G::~G(){
497 delete lshHeader; 502 delete lshHeader;
498 } 503 }
678 683
679 void G::serialize(char* filename, Uns32T serialFormat){ 684 void G::serialize(char* filename, Uns32T serialFormat){
680 int dbfid; 685 int dbfid;
681 char* db; 686 char* db;
682 int dbIsNew=0; 687 int dbIsNew=0;
683 688 FILE* dbFile = 0;
684 // Check requested serialFormat 689 // Check requested serialFormat
685 if(!(serialFormat==O2_SERIAL_FILEFORMAT1 || serialFormat==O2_SERIAL_FILEFORMAT2)) 690 if(!(serialFormat==O2_SERIAL_FILEFORMAT1 || serialFormat==O2_SERIAL_FILEFORMAT2))
686 error("Unrecognized serial file format request: ", "serialize()"); 691 error("Unrecognized serial file format request: ", "serialize()");
687 692
688 // Test to see if file exists 693 // Test to see if file exists
715 serialize_lsh_hashfunctions(dbfid); 720 serialize_lsh_hashfunctions(dbfid);
716 // Write the hashtables in the requested format 721 // Write the hashtables in the requested format
717 if(serialFormat == O2_SERIAL_FILEFORMAT1) 722 if(serialFormat == O2_SERIAL_FILEFORMAT1)
718 serialize_lsh_hashtables_format1(dbfid, !dbIsNew); 723 serialize_lsh_hashtables_format1(dbfid, !dbIsNew);
719 else{ 724 else{
720 FILE* dbFile = fdopen(dbfid, "r+b"); 725 dbFile = fdopen(dbfid, "r+b");
721 if(!dbFile) 726 if(!dbFile)
722 error("Cannot open LSH file for writing",filename); 727 error("Cannot open LSH file for writing",filename);
723 serialize_lsh_hashtables_format2(dbFile, !dbIsNew); 728 serialize_lsh_hashtables_format2(dbFile, !dbIsNew);
724 fflush(dbFile); 729 fflush(dbFile);
725 } 730 }
734 lshHeader->flags|=O2_SERIAL_FILEFORMAT1; 739 lshHeader->flags|=O2_SERIAL_FILEFORMAT1;
735 memcpy((char*)db, (char*)lshHeader, sizeof(SerialHeaderT)); 740 memcpy((char*)db, (char*)lshHeader, sizeof(SerialHeaderT));
736 serial_munmap(db, O2_SERIAL_HEADER_SIZE); // drop mmap 741 serial_munmap(db, O2_SERIAL_HEADER_SIZE); // drop mmap
737 } 742 }
738 serial_close(dbfid); 743 serial_close(dbfid);
744 if(dbFile){
745 fclose(dbFile);
746 dbFile = 0;
747 }
739 } 748 }
740 749
741 // Test to see if core structure and requested format is 750 // Test to see if core structure and requested format is
742 // compatible with currently opened database 751 // compatible with currently opened database
743 int G::serial_can_merge(Uns32T format){ 752 int G::serial_can_merge(Uns32T format){