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()
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);
int i,k=0;
char *str = new char[30];
......
......@@ -47,7 +47,7 @@ CycleStorage::CycleStorage(const char* name, int byte_sz, int inf_sz, int inf_co
CycleStorage::~CycleStorage()
{
fclose(file);
if( file!=NULL ) fclose(file);
}
void* CycleStorage::valPointer(void* pnt)
......@@ -142,7 +142,12 @@ bool CycleStorage::findHead()
bool CycleStorage::checkAttr(int inf_sz, int inf_count, int seek)
{
if( file==NULL ) return false;
fseek(file,seek,0);
if( fseek(file,seek,0)==-1 )
{
fclose(file);
file=NULL;
return false;
}
/*! */
CycleStorageAttr csa;
......@@ -215,11 +220,14 @@ bool CycleStorage::create(const char* name, int byte_sz, int inf_sz, int inf_cou
/*! , */
if(file==NULL)
{
FILE*f=fopen(name,"w");
FILE *f=fopen(name,"w");
if( f==NULL ) return false;
fclose(f);
file = fopen(name, "r+");
}
if( file==NULL ) return false;
if(fseek(file,seekpos,0)==-1) return false;
CycleStorageElem *jrn = (CycleStorageElem*)new char[full_size];
......
......@@ -49,7 +49,7 @@ TableBlockStorage::TableBlockStorage(const char* name, int byte_sz, int key_sz,
TableBlockStorage::~TableBlockStorage()
{
delete mem;
if( mem!=NULL ) delete mem;
if(file!=NULL) fclose(file);
}
......@@ -228,7 +228,8 @@ bool TableBlockStorage::create(const char* name, int byte_sz, int key_sz, int in
if(file==NULL)
{
FILE*f=fopen(name,"w");
FILE *f=fopen(name,"w");
if( f==NULL ) return false;
fclose(f);
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