Commit cfce884a authored by Ivan Donchevskiy's avatar Ivan Donchevskiy

Fixed segmentation error in TableBlockStorage and CycleStorage

parent 4f798df4
...@@ -236,6 +236,10 @@ bool reOpen() ...@@ -236,6 +236,10 @@ bool reOpen()
bool testJournal1(void) bool testJournal1(void)
{ {
CycleStorage *jjj = new CycleStorage();
jjj->create("/dev/hdb2",bj_size,30,32000,seek);
delete jjj;
CycleStorage j("big_file.test",bj_size,30,32000,seek,true); CycleStorage j("big_file.test",bj_size,30,32000,seek,true);
int i,k=0; int i,k=0;
char *str = new char[30]; char *str = new char[30];
......
...@@ -47,7 +47,7 @@ CycleStorage::CycleStorage(const char* name, int byte_sz, int inf_sz, int inf_co ...@@ -47,7 +47,7 @@ CycleStorage::CycleStorage(const char* name, int byte_sz, int inf_sz, int inf_co
CycleStorage::~CycleStorage() CycleStorage::~CycleStorage()
{ {
fclose(file); if( file!=NULL ) fclose(file);
} }
void* CycleStorage::valPointer(void* pnt) void* CycleStorage::valPointer(void* pnt)
...@@ -142,7 +142,12 @@ bool CycleStorage::findHead() ...@@ -142,7 +142,12 @@ bool CycleStorage::findHead()
bool CycleStorage::checkAttr(int inf_sz, int inf_count, int seek) bool CycleStorage::checkAttr(int inf_sz, int inf_count, int seek)
{ {
if( file==NULL ) return false; if( file==NULL ) return false;
fseek(file,seek,0); if( fseek(file,seek,0)==-1 )
{
fclose(file);
file=NULL;
return false;
}
/*! */ /*! */
CycleStorageAttr csa; CycleStorageAttr csa;
...@@ -215,11 +220,14 @@ bool CycleStorage::create(const char* name, int byte_sz, int inf_sz, int inf_cou ...@@ -215,11 +220,14 @@ bool CycleStorage::create(const char* name, int byte_sz, int inf_sz, int inf_cou
/*! , */ /*! , */
if(file==NULL) if(file==NULL)
{ {
FILE*f=fopen(name,"w"); FILE *f=fopen(name,"w");
if( f==NULL ) return false;
fclose(f); fclose(f);
file = fopen(name, "r+"); file = fopen(name, "r+");
} }
if( file==NULL ) return false;
if(fseek(file,seekpos,0)==-1) return false; if(fseek(file,seekpos,0)==-1) return false;
CycleStorageElem *jrn = (CycleStorageElem*)new char[full_size]; CycleStorageElem *jrn = (CycleStorageElem*)new char[full_size];
......
...@@ -49,7 +49,7 @@ TableBlockStorage::TableBlockStorage(const char* name, int byte_sz, int key_sz, ...@@ -49,7 +49,7 @@ TableBlockStorage::TableBlockStorage(const char* name, int byte_sz, int key_sz,
TableBlockStorage::~TableBlockStorage() TableBlockStorage::~TableBlockStorage()
{ {
delete mem; if( mem!=NULL ) delete mem;
if(file!=NULL) fclose(file); if(file!=NULL) fclose(file);
} }
...@@ -228,7 +228,8 @@ bool TableBlockStorage::create(const char* name, int byte_sz, int key_sz, int in ...@@ -228,7 +228,8 @@ bool TableBlockStorage::create(const char* name, int byte_sz, int key_sz, int in
if(file==NULL) if(file==NULL)
{ {
FILE*f=fopen(name,"w"); FILE *f=fopen(name,"w");
if( f==NULL ) return false;
fclose(f); fclose(f);
file = fopen(name, "r+"); file = fopen(name, "r+");
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment