Refcounting ConceptData, so not freeing it twice, which causes the GPF.
Fixed some memory leaks. Fixing a memory overwrite in BreeDict.cxx
This commit is contained in:
Andreas Bille
2001-07-05 17:50:40 +00:00
parent 7187b23ccd
commit 4ca45e5081
8 changed files with 140 additions and 92 deletions

View File

@@ -2,9 +2,9 @@
*
* $RCSfile: Block.cxx,v $
*
* $Revision: 1.2 $
* $Revision: 1.3 $
*
* last change: $Author: abi $ $Date: 2001-05-10 15:25:10 $
* last change: $Author: abi $ $Date: 2001-07-05 18:50:40 $
*
* The Contents of this file are made available subject to the terms of
* either of the following licenses
@@ -58,6 +58,9 @@
*
*
************************************************************************/
#ifndef _RTL_MEMORY_H_
#include <rtl/memory.h>
#endif
#ifndef _XMLSEARCH_DB_BLOCK_HXX_
#include <db/Block.hxx>
#endif
@@ -88,6 +91,7 @@ Block::Block( const DBEnv* dbenv )
dataL_( dbenv->getDataLen() ),
data_( new sal_Int8[ dbenv->getDataLen() ] )
{
rtl_zeroMemory( data_,dataL_ );
}

View File

@@ -2,9 +2,9 @@
*
* $RCSfile: BtreeDict.cxx,v $
*
* $Revision: 1.7 $
* $Revision: 1.8 $
*
* last change: $Author: abi $ $Date: 2001-06-22 14:13:18 $
* last change: $Author: abi $ $Date: 2001-07-05 18:50:40 $
*
* The Contents of this file are made available subject to the terms of
* either of the following licenses
@@ -368,7 +368,7 @@ BtreeDict::BtreeDict( const util::IndexAccessor& indexAccessor ) throw( IOExcept
{
sal_Int32 len = SCHEMA->length();
char* bff = new char[ 1 + len ];
bff[ 1 + len ] = 0;
bff[ len ] = 0;
SCHEMA->readBytes( reinterpret_cast<sal_Int8*>( bff ),len );
delete SCHEMA;

View File

@@ -2,9 +2,9 @@
*
* $RCSfile: ConceptData.cxx,v $
*
* $Revision: 1.3 $
* $Revision: 1.4 $
*
* last change: $Author: abi $ $Date: 2001-06-18 12:10:12 $
* last change: $Author: abi $ $Date: 2001-07-05 18:50:40 $
*
* The Contents of this file are made available subject to the terms of
* either of the following licenses
@@ -88,26 +88,32 @@ ConceptData::ConceptData( sal_Int32 id,
role_( sal_uInt8( role & 0xF ) ),
penalty_( score ),
ctx_( contextTables ),
next_( 0 )
next_( 0 ),
m_nRefcount( 0 )
{
}
ConceptData::~ConceptData()
{
}
void ConceptData::runBy( std::vector< Query* >& queries )
{
ConceptData* cd = this;
rtl::Reference< ConceptData > cd( this );
do
{
Query* query = queries[ cd->queryNo_ ];
query->updateEstimate( cd->role_,cd->penalty_ );
}
while( cd = cd->next_ );
while( (cd = cd->next_).is() );
}
void ConceptData::addLast( ConceptData* r )
{
if( next_ )
if( next_.is() )
next_->addLast( r );
else
next_ = r;
@@ -119,15 +125,15 @@ void ConceptData::generateFillers( std::vector< RoleFiller* >& array, sal_Int32
if( array[ queryNo_ ] != RoleFiller::STOP() ) // not 'prohibited'
{
sal_Int32 wcl = ctx_->wordContextLin( pos );
RoleFiller* p = new RoleFiller( nColumns_,
this,
role_,
pos,
wcl,
pos + proximity_ );
p->use( array, queryNo_ );
roleFillers_.push_back( new RoleFiller( nColumns_,
this,
role_,
pos,
wcl,
pos + proximity_ ) );
roleFillers_.back()->use( array, queryNo_ );
}
// !!! maybe eliminate tail recursion
if( next_ )
if( next_.is() )
next_->generateFillers( array,pos );
}

View File

@@ -2,9 +2,9 @@
*
* $RCSfile: ContextTables.cxx,v $
*
* $Revision: 1.4 $
* $Revision: 1.5 $
*
* last change: $Author: abi $ $Date: 2001-06-22 10:12:51 $
* last change: $Author: abi $ $Date: 2001-07-05 18:50:40 $
*
* The Contents of this file are made available subject to the terms of
* either of the following licenses
@@ -58,6 +58,10 @@
*
*
************************************************************************/
#ifndef _rtl_MEMORY_H_
#include <rtl/memory.h>
#endif
#ifndef _XMLSEARCH_QE_CONTEXTTABLES_HXX_
#include <qe/ContextTables.hxx>
#endif
@@ -76,6 +80,21 @@ Tables::Tables( ContextTables* p )
linkTypesCached_( new sal_Int32[ linkTypesCachedL_ = p->linkTypesL_ ] ),
seqNumbersCached_( new sal_Int32[ seqNumbersCachedL_ = p->seqNumbersL_ ] )
{
rtl_copyMemory( (void*)initialWordsCached_,
(void*)p->initialWords_,
sizeof(sal_Int32) * p->initialWordsL_ );
rtl_copyMemory( (void*)destsCached_,
(void*)p->dests_,
sizeof(sal_Int32) * p->destsL_ );
rtl_copyMemory( (void*)linkTypesCached_,
(void*)p->linkTypes_,
sizeof(sal_Int32) * p->linkTypesL_ );
rtl_copyMemory( (void*)seqNumbersCached_,
(void*)p->seqNumbers_,
sizeof(sal_Int32) * p->seqNumbersL_ );
}
@@ -129,7 +148,6 @@ ContextTables::ContextTables( const std::vector< sal_Int32 >& offsets,
contextData_( contextData ),
linkNamesL_( linkNamesL ),
linkNames_( linkNames ),
cache_( offsets.size() ),
initialWordsL_( 0 ),
initialWords_( 0 ),
@@ -179,6 +197,7 @@ void ContextTables::setMicroindex( sal_Int32 docNo ) throw( excep::XmlSearchExce
auxArray_.clear();
compr.ascDecode( kTable_[0],auxArray_ ); // _initialWords
delete[] initialWords_;
initialWords_ = new sal_Int32[ initialWordsL_ = auxArray_.size() ];
sal_Int32 k;
for( k = 0; k < initialWordsL_; ++k ) //?opt
@@ -190,13 +209,16 @@ void ContextTables::setMicroindex( sal_Int32 docNo ) throw( excep::XmlSearchExce
compr.decode( kTable_[1],auxArray_ ); // _dests
auxArray_.push_back( -1 ); // sentinel, root
delete[] dests_;
dests_ = new sal_Int32[ destsL_ = auxArray_.size() ];
for( k = 0; k < destsL_; ++k ) //?opt
dests_[k] = auxArray_[k];
delete[] linkTypes_;
linkTypes_ = new sal_Int32[ linkTypesL_ = destsL_ - nTextNodes_ - 1 ];
compr.decode( kTable_[2],linkTypes_ );
delete[] seqNumbers_;
seqNumbers_ = new sal_Int32[ seqNumbersL_ = destsL_ - 1 ];
compr.decode( kTable_[ 3 ],seqNumbers_ );
@@ -204,6 +226,7 @@ void ContextTables::setMicroindex( sal_Int32 docNo ) throw( excep::XmlSearchExce
}
lastDocNo_ = docNo;
delete[] markers_;
markers_ = new sal_Int32[ markersL_ = destsL_ ];
}
initialWordsIndex_ = 0;
@@ -410,6 +433,19 @@ void ContextTables::resetContextSearch()
}
sal_Int32 ContextTables::wordContextLin(sal_Int32 wordNumber)
{
for (sal_Int32 i = initialWordsIndex_; i < nTextNodes_; ++i )
if (initialWords_[i] > wordNumber)
{ // first such i
// - 1 if wordNumbers can be the same
initialWordsIndex_ = i; // cached to speed up next search
return i - 1;
}
return nTextNodes_ - 1;
}
// void ContextTables::appendSegment( sal_Int32 context,rtl::OUStringBuffer& result )
// {
// result.append( context < nTextNodes_ ?
@@ -686,15 +722,9 @@ void ContextTables::resetContextSearch()
*/
sal_Int32 ContextTables::wordContextLin(sal_Int32 wordNumber)
{
for (sal_Int32 i = initialWordsIndex_; i < nTextNodes_; ++i )
if (initialWords_[i] > wordNumber)
{ // first such i
// - 1 if wordNumbers can be the same
initialWordsIndex_ = i; // cached to speed up next search
return i - 1;
}
return nTextNodes_ - 1;
}

View File

@@ -2,9 +2,9 @@
*
* $RCSfile: DocGenerator.cxx,v $
*
* $Revision: 1.3 $
* $Revision: 1.4 $
*
* last change: $Author: abi $ $Date: 2001-06-06 14:48:47 $
* last change: $Author: abi $ $Date: 2001-07-05 18:50:40 $
*
* The Contents of this file are made available subject to the terms of
* either of the following licenses
@@ -87,7 +87,8 @@ RoleFiller::RoleFiller()
limit_( 0 ),
parentContext_( 0 ),
next_( 0 ),
fillers_( 0 )
fillers_( 0 ),
m_nRefcount( 0 )
{
}
@@ -101,7 +102,8 @@ RoleFiller::RoleFiller( sal_Int32 nColumns,
: next_( 0 ),
conceptData_( first ),
fixedRole_( sal_uInt8( role & 0xF ) ), // primary/constitutive concept/role
fillers_( nColumns )
fillers_( nColumns ),
m_nRefcount( 0 )
{
filled_ = sal_Int16( 1 << fixedRole_ );
begin_ = pos; // offset in file
@@ -119,7 +121,9 @@ RoleFiller::RoleFiller( sal_Int32 nColumns,
RoleFiller::~RoleFiller()
{
for( sal_uInt32 i = 0; i < fillers_.size(); ++i )
delete fillers_[i];
;
// if( fillers_[i] != this )
// delete fillers_[i];
}
@@ -193,7 +197,7 @@ sal_Int32 RoleFiller::getConcept()
void RoleFiller::use( std::vector< RoleFiller*>& place,sal_Int32 query )
{
RoleFiller* rf;
RoleFiller* rf,*tmp;
if( rf = place[ query ] )
{
place[ query ] = this; // put at the head of list
@@ -317,7 +321,9 @@ void NextDocGeneratorHeap::step() throw( excep::XmlSearchException )
heapify(0);
else if ( heapSize_ > 1 )
{
delete heap_[0];
heap_[0] = heap_[--heapSize_];
heap_[ heapSize_ ] = 0;
heapify(0);
}
else
@@ -363,8 +369,6 @@ ConceptGroupGenerator::ConceptGroupGenerator( sal_Int32 dataL,sal_Int8* data,sal
bits_( new util::ByteArrayDecompressor( dataL,data,index ) ),
table_( NConceptsInGroup )
{
for( sal_Int32 i = 0; i < NConceptsInGroup; ++i )
table_[i] = 0;
}
@@ -396,7 +400,7 @@ bool ConceptGroupGenerator::next() throw( excep::XmlSearchException )
while( bits_->readNext( k1_,this ) )
{
sal_Int32 bla = bits_->read( k2_ );
if( cData_ = table_[ bla ] )
if( ( cData_ = table_[ bla ] ).is() )
return true;
}
return false;
@@ -420,10 +424,7 @@ void ConceptGroupGenerator::init( sal_Int32 bytesL,sal_Int8* bytes,sal_Int32 ind
bits_ = new util::ByteArrayDecompressor( bytesL,bytes,index );
last_ = 0;
for( sal_Int32 i = 0;i < NConceptsInGroup; i++ )
{
// delete table_[i];
table_[i] = 0;
}
}
@@ -511,6 +512,7 @@ bool GeneratorHeap::next( std::vector< RoleFiller* >& array ) throw( xmlsearch::
{
delete heap_[0];
heap_[0] = heap_[--heapSize_];
heap_[heapSize_] = 0;
}
else
{

View File

@@ -2,9 +2,9 @@
*
* $RCSfile: Query.cxx,v $
*
* $Revision: 1.3 $
* $Revision: 1.4 $
*
* last change: $Author: abi $ $Date: 2001-05-11 12:39:12 $
* last change: $Author: abi $ $Date: 2001-07-05 18:50:40 $
*
* The Contents of this file are made available subject to the terms of
* either of the following licenses
@@ -153,10 +153,7 @@ QueryHit* HitStore::firstBestQueryHit()
{
if( free_ > 0)
{
// for( sal_uInt32 i = 0; i < heap_.size(); ++i )
// printf( " number = %x\n",heap_[i] );
CompareQueryHit bla;
CompareQueryHit bla;
heap_.resize( free_ );
std::stable_sort( heap_.begin(),heap_.end(),bla );
index_ = 0;
@@ -247,13 +244,15 @@ Query::Query( XmlIndex* env,
ctx_( env ? env->getContextInfo() : 0 ),
nColumns_( nColumns ),
nHitsRequested_( nHits ),
missingPenalty_( new double[ missingPenaltyL_ = nColumns_ ] ) ,
upperboundTemplate_( new double[ upperboundTemplateL_ = nColumns_ ] ),
missingPenaltyL_( nColumns ),
missingPenalty_( new double[ nColumns ] ),
upperboundTemplateL_( nColumns ),
upperboundTemplate_( new double[ nColumns ] ),
penaltiesL_( missingPenaltiesL ),
penalties_( missingPenalties ),
currentStandard_( nColumns * MissingTermPenalty - 0.0001 ),
missingTermsPenalty_( 0.0 ),
store_( currentStandard_,nHits,nColumns ),
store_( nColumns * MissingTermPenalty - 0.0001,nHits,nColumns ),
ignoredElementsL_( 0 ),
ignoredElements_( 0 )
{

View File

@@ -2,9 +2,9 @@
*
* $RCSfile: QueryProcessor.cxx,v $
*
* $Revision: 1.5 $
* $Revision: 1.6 $
*
* last change: $Author: abi $ $Date: 2001-06-19 13:41:05 $
* last change: $Author: abi $ $Date: 2001-07-05 18:50:40 $
*
* The Contents of this file are made available subject to the terms of
* either of the following licenses

View File

@@ -2,9 +2,9 @@
*
* $RCSfile: Search.cxx,v $
*
* $Revision: 1.4 $
* $Revision: 1.5 $
*
* last change: $Author: abi $ $Date: 2001-06-06 14:48:47 $
* last change: $Author: abi $ $Date: 2001-07-05 18:50:40 $
*
* The Contents of this file are made available subject to the terms of
* either of the following licenses
@@ -99,10 +99,10 @@ public:
{
}
virtual ConceptData* makeConceptData( sal_Int32 query,
sal_Int32 col,
sal_Int32 concept,
double score )
ConceptData* makeConceptData( sal_Int32 col,
sal_Int32 concept,
double penalty,
sal_Int32 queryNo )
{
return &conceptDataInstance_;
}
@@ -203,7 +203,7 @@ void ConceptData1::generateFillers( std::vector< RoleFiller* >& array, sal_Int32
}
}
if( next_ )
if( next_.is() )
next_->generateFillers( array,pos );
}
@@ -232,6 +232,8 @@ public:
Query* makeQuery( XmlIndex* env,const rtl::OUString& context,sal_Int32 nColumns,sal_Int32 nHits);
Query* empty() { return &emptyQueryInstance_; }
private:
EmptyQuery emptyQueryInstance_;
@@ -298,17 +300,17 @@ Search::Search( XmlIndex* env )
Search::~Search()
{
delete queryFactory_;
sal_uInt32 i;
Query* stopq = queryFactory_ ? queryFactory_->empty() : 0;
ConceptData* stopc = stopq ? stopq->makeConceptData( 0,0,0.0,0 ) : 0;
for( i = 0; i < queries_.size(); ++i )
delete queries_[i];
for( i = 0; i < conceptData_.size(); ++i )
delete conceptData_[i];
if( queries_[i] != stopq )
delete queries_[i];
delete[] concepts_;
delete queryFactory_;
}
@@ -360,7 +362,7 @@ void Search::startSearch()
{
for (j = i + 1; j < free2_; j++)
{
if( conceptData_[i]->crqEquals( conceptData_[j] ) )
if( conceptData_[i]->crqEquals( conceptData_[j].get() ) )
conceptData_[j] = 0;
else
i = j;
@@ -372,10 +374,10 @@ void Search::startSearch()
{
for (j = i + 1; j < free2_; j++ )
{
if( conceptData_[j] )
if( conceptData_[i]->cEquals( conceptData_[j] ) )
if( conceptData_[j].is() )
if( conceptData_[i]->cEquals( conceptData_[j].get() ) )
{
conceptData_[i]->addLast( conceptData_[j] );
conceptData_[i]->addLast( conceptData_[j].get() );
conceptData_[j] = 0;
}
else
@@ -386,11 +388,11 @@ void Search::startSearch()
// densify
for( i = 0; i < free2_ - 1; i++)
{
if( ! conceptData_[i] )
if( ! conceptData_[i].is() )
{
for( j = i + 1; j < free2_; j++)
{
if (conceptData_[j] )
if (conceptData_[j].is() )
{
conceptData_[i] = conceptData_[j];
conceptData_[j] = 0;
@@ -402,9 +404,9 @@ void Search::startSearch()
// set up new document generators
nextDocGenHeap_.reset();
for( i = 0; i < free2_ && conceptData_[i]; i++)
for( i = 0; i < free2_ && conceptData_[i].is(); i++)
{
NextDocGenerator* gen = new NextDocGenerator( conceptData_[i],env_ );
NextDocGenerator* gen = new NextDocGenerator( conceptData_[i].get(),env_ );
try
{
sal_Int32 doc;
@@ -441,7 +443,7 @@ void Search::addTerm( sal_Int32 col,sal_Int32 concept,double score )
if( sal_uInt32( free2_ ) == conceptData_.size() )
{
conceptData_.push_back( 0 );
conceptVisitor_ = &conceptData_[0];
// conceptVisitor_ = &conceptData_[0];
}
conceptData_[ free2_++ ] = cd;
}
@@ -495,11 +497,13 @@ void Search::searchDocument()
genHeap_.reset();
}
while( nextDocGenHeap_.isNonEmpty() );
for( sal_Int32 i = 0; i < start.size(); ++i )
if( start[i] != RoleFiller::STOP() )
delete start[i];
}
extern void print_rtl_OUString( const rtl::OUString bla );
sal_Int32 Search::nextDocument( std::vector< RoleFiller* >& start ) throw( xmlsearch::excep::XmlSearchException )
{
@@ -520,7 +524,7 @@ sal_Int32 Search::nextDocument( std::vector< RoleFiller* >& start ) throw( xmlse
{
docConcepts_.push_back( nextDocGenHeap_.getConcept() );
queryMasks_.push_back( nextDocGenHeap_.getQueryMask() );
ConceptData *conceptData = ( conceptData_[ index++ ] = nextDocGenHeap_.getTerms() );
ConceptData *conceptData = ( conceptData_[ index++ ] = nextDocGenHeap_.getTerms() ).get();
conceptData->runBy( queries_ );
nextDocGenHeap_.step();
}
@@ -559,7 +563,7 @@ sal_Int32 Search::nextDocument( std::vector< RoleFiller* >& start ) throw( xmlse
ConceptGroupGenerator* gen;
// !!! don't gather Fillers for disinterested Queries
if( openDocumentIndex( document_ ) )
{// multi group
{ // multi group
// set up all needed generators
sal_Int32 i = 0;
while( ( queryMasks_[i] & voteMask ) == 0 )
@@ -568,10 +572,11 @@ sal_Int32 Search::nextDocument( std::vector< RoleFiller* >& start ) throw( xmlse
sal_Int32 c = docConcepts_[i];
sal_Int32 group = 0;
// find first group
while( c > maxConcepts_[ group ] && ++group < limit_ )
while( /*group < maxConcepts_.size() &&*/
c > maxConcepts_[ group ] && ++group < limit_ )
;
gen = makeGenerator( group );
gen->addTerms( indexOf(c), conceptData_[i] );
gen->addTerms( indexOf(c),conceptData_[i].get() );
for( ++i; i < index; i++ )
if( ( queryMasks_[i] & voteMask ) > 0 )
@@ -580,10 +585,12 @@ sal_Int32 Search::nextDocument( std::vector< RoleFiller* >& start ) throw( xmlse
if( c > max_ )
{ // need to find another group
// assert(group < _limit);
while( c > maxConcepts_[ group ] && ++group < limit_ ) ;
while( /*group < maxConcepts_.size() &&*/
c > maxConcepts_[ group ] && ++group < limit_ )
;
gen = makeGenerator( group );
}
gen->addTerms( indexOf(c), conceptData_[i] );
gen->addTerms( indexOf(c),conceptData_[i].get() );
}
return 0;
}
@@ -591,7 +598,7 @@ sal_Int32 Search::nextDocument( std::vector< RoleFiller* >& start ) throw( xmlse
{ // single group
for( sal_Int32 i = 0; i < index; i++ )
if( queryMasks_[i] & voteMask )
firstGenerator_.addTerms( indexOf( docConcepts_[i] ),conceptData_[i] );
firstGenerator_.addTerms( indexOf( docConcepts_[i] ),conceptData_[i].get() );
return 1;
}
}
@@ -667,7 +674,7 @@ ConceptGroupGenerator* Search::makeGenerator( sal_Int32 group )
// initialize generator
ConceptGroupGenerator* gen =
new ConceptGroupGenerator( dataL_,data_,index,kTable_[ 2*group + 1 ] );
new ConceptGroupGenerator( dataL_,data_,index,kTable_[ 1 + 2*group ] );
// decode concept table
nConcepts_ = gen->decodeConcepts( kTable_[2*group],shift,concepts_ );
@@ -704,17 +711,17 @@ sal_Int32 Search::indexOf(sal_Int32 concept) throw( excep::XmlSearchException )
sal_Int32 Search::partition( sal_Int32 p,sal_Int32 r )
{
ConceptData* x = conceptData_[ ((p + r) >> 1) & 0x7FFFFFFF ];
rtl::Reference< ConceptData > x = conceptData_[ ((p + r) >> 1) & 0x7FFFFFFF ];
sal_Int32 i = p - 1, j = r + 1;
while( true )
{
while( x->compareWith( conceptData_[--j] ) )
while( x->compareWith( conceptData_[--j].get() ) )
;
while( conceptData_[++i]->compareWith( x ) )
while( conceptData_[++i]->compareWith( x.get() ) )
;
if( i < j )
{
ConceptData* t = conceptData_[i];
rtl::Reference< ConceptData > t = conceptData_[i];
conceptData_[i] = conceptData_[j];
conceptData_[j] = t;
}