fix: lack of delete[] in KVstore.cpp
This commit is contained in:
parent
ae5e610acc
commit
a2cce262ad
|
@ -149,11 +149,8 @@ KVstore::getEntityInDegree(TYPE_ENTITY_LITERAL_ID _entity_id) const
|
|||
|
||||
//if this is a long list, then we should remove itself after copying
|
||||
//otherwise, we should not free the list memory
|
||||
if(VList::listNeedDelete(_len))
|
||||
{
|
||||
delete[] _tmp;
|
||||
delete[] _tmp;
|
||||
//_tmp = NULL;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
@ -174,11 +171,8 @@ KVstore::getEntityOutDegree(TYPE_ENTITY_LITERAL_ID _entity_id) const
|
|||
|
||||
//if this is a long list, then we should remove itself after copying
|
||||
//otherwise, we should not free the list memory
|
||||
if(VList::listNeedDelete(_len))
|
||||
{
|
||||
delete[] _tmp;
|
||||
delete[] _tmp;
|
||||
//_tmp = NULL;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
@ -199,12 +193,7 @@ KVstore::getLiteralDegree(TYPE_ENTITY_LITERAL_ID _literal_id) const
|
|||
|
||||
//if this is a long list, then we should remove itself after copying
|
||||
//otherwise, we should not free the list memory
|
||||
if(VList::listNeedDelete(_len))
|
||||
{
|
||||
delete[] _tmp;
|
||||
//_tmp = NULL;
|
||||
}
|
||||
|
||||
delete[] _tmp;
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
@ -224,11 +213,8 @@ KVstore::getPredicateDegree(TYPE_PREDICATE_ID _predicate_id) const
|
|||
|
||||
//if this is a long list, then we should remove itself after copying
|
||||
//otherwise, we should not free the list memory
|
||||
if(VList::listNeedDelete(_len))
|
||||
{
|
||||
delete[] _tmp;
|
||||
delete[] _tmp;
|
||||
//_tmp = NULL;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
@ -264,12 +250,8 @@ KVstore::getSubjectPredicateDegree(TYPE_ENTITY_LITERAL_ID _subid, TYPE_PREDICATE
|
|||
|
||||
//if this is a long list, then we should remove itself after copying
|
||||
//otherwise, we should not free the list memory
|
||||
if(VList::listNeedDelete(_len))
|
||||
{
|
||||
delete[] _tmp;
|
||||
delete[] _tmp;
|
||||
//_tmp = NULL;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
@ -304,12 +286,8 @@ KVstore::getObjectPredicateDegree(TYPE_ENTITY_LITERAL_ID _objid, TYPE_PREDICATE_
|
|||
|
||||
//if this is a long list, then we should remove itself after copying
|
||||
//otherwise, we should not free the list memory
|
||||
if(VList::listNeedDelete(_len))
|
||||
{
|
||||
delete[] _tmp;
|
||||
delete[] _tmp;
|
||||
//_tmp = NULL;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
@ -581,11 +559,10 @@ KVstore::updateInsert_s2values(TYPE_ENTITY_LITERAL_ID _sub_id, TYPE_PREDICATE_ID
|
|||
_values[j] = _tmp[i];
|
||||
}
|
||||
}
|
||||
|
||||
this->setValueByKey(this->subID2values, _sub_id, (char*)_values, sizeof(unsigned) * _values_len);
|
||||
//delete[] _values;
|
||||
}
|
||||
|
||||
delete []_tmp;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -677,7 +654,7 @@ KVstore::updateRemove_s2values(TYPE_ENTITY_LITERAL_ID _sub_id, TYPE_PREDICATE_ID
|
|||
this->setValueByKey(this->subID2values, _sub_id, (char*)_values, sizeof(unsigned) * _values_len);
|
||||
//delete[] _values;
|
||||
}
|
||||
|
||||
delete []_tmp;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -805,7 +782,7 @@ KVstore::updateInsert_o2values(TYPE_ENTITY_LITERAL_ID _sub_id, TYPE_PREDICATE_ID
|
|||
this->setValueByKey(this->objID2values, _obj_id, (char*)_values, sizeof(unsigned) * _values_len);
|
||||
//delete[] _values;
|
||||
}
|
||||
|
||||
delete []_tmp;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -885,7 +862,7 @@ KVstore::updateRemove_o2values(TYPE_ENTITY_LITERAL_ID _sub_id, TYPE_PREDICATE_ID
|
|||
this->setValueByKey(this->objID2values, _obj_id, (char*)_values, sizeof(unsigned) * _values_len);
|
||||
//delete[] _values;
|
||||
}
|
||||
|
||||
delete []_tmp;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -958,7 +935,7 @@ KVstore::updateInsert_p2values(TYPE_ENTITY_LITERAL_ID _sub_id, TYPE_PREDICATE_ID
|
|||
this->setValueByKey(this->preID2values, _pre_id, (char*)_values, sizeof(unsigned) * _values_len);
|
||||
//delete[] _values;
|
||||
}
|
||||
|
||||
delete []_tmp;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -998,7 +975,7 @@ KVstore::updateRemove_p2values(TYPE_ENTITY_LITERAL_ID _sub_id, TYPE_PREDICATE_ID
|
|||
this->setValueByKey(this->preID2values, _pre_id, (char*)_values, sizeof(unsigned) * _values_len);
|
||||
//delete[] _values;
|
||||
}
|
||||
|
||||
delete []_tmp;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -1122,6 +1099,7 @@ KVstore::open_id2entity(int _mode)
|
|||
bool
|
||||
KVstore::close_id2entity()
|
||||
{
|
||||
|
||||
if (this->id2entity == NULL)
|
||||
{
|
||||
return true;
|
||||
|
@ -1153,40 +1131,23 @@ KVstore::getEntityByID(TYPE_ENTITY_LITERAL_ID _id) const
|
|||
}
|
||||
|
||||
//NOTICE: no need to add \0 at last if we indicate the length
|
||||
// cout << "in getEntityByID: ";
|
||||
// cout << _tmp << endl;
|
||||
// unsigned length = _len + 1;
|
||||
// char * debug = new char [length];
|
||||
// memcpy(debug, _tmp, _len);
|
||||
// debug[_len] = '\0';
|
||||
// cout << "in getEntityByID (add): ";
|
||||
// _tmp = debug;
|
||||
//cout << _tmp << endl;
|
||||
|
||||
string _ret = string(_tmp, _len);
|
||||
delete[] _tmp;
|
||||
//CONSIDER: represent "abc" by 4 chars with length=4, and construct with string(str) directly
|
||||
|
||||
//if(_id == 62)
|
||||
//{
|
||||
//cout<<"check 62: "<<_ret<<endl;
|
||||
//char* nstr = new char[_len+1];
|
||||
//memcpy(nstr, _tmp, _len);
|
||||
//nstr[_len] = '\0';
|
||||
//cout<<"check 62: "<<nstr<<endl;
|
||||
//for(int k = 0; k < _len; ++k)
|
||||
//{
|
||||
//cout<<_tmp[k]<<" ";
|
||||
//}cout<<endl;
|
||||
//delete[] nstr;
|
||||
//}
|
||||
|
||||
//NOTICE: if there is messy code, then int(char) will < 0, otherwise not
|
||||
//bool invalid = false;
|
||||
//for(unsigned i = 0; i < _len; ++i)
|
||||
//{
|
||||
//if(int(_ret[i])<0)
|
||||
//{
|
||||
//invalid = true;
|
||||
//break;
|
||||
//}
|
||||
//}
|
||||
//if(invalid)
|
||||
//{
|
||||
//cout<<"error in kvstore: "<<_id<<" "<<_ret<<endl;
|
||||
//cout<<"length: "<<_len<<" "<<_tmp<<" "<<_tmp[0]<<endl;
|
||||
//}
|
||||
|
||||
delete []_tmp;
|
||||
// cout << "string is: " << _ret << endl;
|
||||
// string test1 = _ret;
|
||||
// test1.append('\0');
|
||||
// cout << "test1 is " << test1 << endl;
|
||||
//cout << "test2 is " << test2 << endl;
|
||||
return _ret;
|
||||
}
|
||||
|
||||
|
@ -1199,8 +1160,6 @@ KVstore::setEntityByID(TYPE_ENTITY_LITERAL_ID _id, string _entity)
|
|||
char* str = new char[len];
|
||||
memcpy(str, _entity.c_str(), len);
|
||||
|
||||
//cout<<"check 62: "<<this->getEntityByID(62)<<endl;
|
||||
|
||||
return this->addValueByKey(this->id2entity, _id, str, len);
|
||||
}
|
||||
|
||||
|
@ -1321,8 +1280,7 @@ KVstore::getPredicateByID(TYPE_PREDICATE_ID _id) const
|
|||
return "";
|
||||
}
|
||||
string _ret = string(_tmp, _len);
|
||||
delete[] _tmp;
|
||||
|
||||
delete []_tmp;
|
||||
return _ret;
|
||||
}
|
||||
|
||||
|
@ -1457,22 +1415,7 @@ KVstore::getLiteralByID(TYPE_ENTITY_LITERAL_ID _id) const
|
|||
return "";
|
||||
}
|
||||
string _ret = string(_tmp, _len);
|
||||
delete[] _tmp;
|
||||
|
||||
//bool invalid = false;
|
||||
//for(unsigned i = 0; i < _len; ++i)
|
||||
//{
|
||||
//if(int(_ret[i])<0)
|
||||
//{
|
||||
//invalid = true;
|
||||
//break;
|
||||
//}
|
||||
//}
|
||||
//if(invalid)
|
||||
//{
|
||||
//cout<<"error in kvstore: "<<_id<<" "<<_ret<<endl;
|
||||
//}
|
||||
|
||||
delete []_tmp;
|
||||
return _ret;
|
||||
}
|
||||
|
||||
|
@ -1646,11 +1589,11 @@ KVstore::getpreIDlistBysubID(TYPE_ENTITY_LITERAL_ID _subid, unsigned*& _preidlis
|
|||
|
||||
//if this is a long list, then we should remove itself after copying
|
||||
//otherwise, we should not free the list memory
|
||||
//if(VList::listNeedDelete(_len))
|
||||
//{
|
||||
// if(VList::listNeedDelete(_len))
|
||||
// {
|
||||
delete[] _tmp;
|
||||
//_tmp = NULL;
|
||||
//}
|
||||
// }
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -1684,11 +1627,11 @@ KVstore::getobjIDlistBysubID(TYPE_ENTITY_LITERAL_ID _subid, unsigned*& _objidlis
|
|||
|
||||
//if this is a long list, then we should remove itself after copying
|
||||
//otherwise, we should not free the list memory
|
||||
//if(VList::listNeedDelete(_len))
|
||||
//{
|
||||
// if(VList::listNeedDelete(_len))
|
||||
// {
|
||||
delete[] _tmp;
|
||||
//_tmp = NULL;
|
||||
//}
|
||||
// }
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -1734,11 +1677,11 @@ KVstore::getobjIDlistBysubIDpreID(TYPE_ENTITY_LITERAL_ID _subid, TYPE_PREDICATE_
|
|||
|
||||
//if this is a long list, then we should remove itself after copying
|
||||
//otherwise, we should not free the list memory
|
||||
//if(VList::listNeedDelete(_len))
|
||||
//{
|
||||
// if(VList::listNeedDelete(_len))
|
||||
// {
|
||||
delete[] _tmp;
|
||||
//_tmp = NULL;
|
||||
//}
|
||||
// }
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -1782,11 +1725,11 @@ KVstore::getpreIDobjIDlistBysubID(TYPE_ENTITY_LITERAL_ID _subid, unsigned*& _pre
|
|||
|
||||
//if this is a long list, then we should remove itself after copying
|
||||
//otherwise, we should not free the list memory
|
||||
//if(VList::listNeedDelete(_len))
|
||||
//{
|
||||
// if(VList::listNeedDelete(_len))
|
||||
// {
|
||||
delete[] _tmp;
|
||||
//_tmp = NULL;
|
||||
//}
|
||||
// }
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -1922,11 +1865,11 @@ KVstore::getpreIDlistByobjID(TYPE_ENTITY_LITERAL_ID _objid, unsigned*& _preidlis
|
|||
|
||||
//if this is a long list, then we should remove itself after copying
|
||||
//otherwise, we should not free the list memory
|
||||
//if(VList::listNeedDelete(_len))
|
||||
//{
|
||||
// if(VList::listNeedDelete(_len))
|
||||
// {
|
||||
delete[] _tmp;
|
||||
//_tmp = NULL;
|
||||
//}
|
||||
// }
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -1954,11 +1897,11 @@ KVstore::getsubIDlistByobjID(TYPE_ENTITY_LITERAL_ID _objid, unsigned*& _subidlis
|
|||
|
||||
//if this is a long list, then we should remove itself after copying
|
||||
//otherwise, we should not free the list memory
|
||||
//if(VList::listNeedDelete(_len))
|
||||
//{
|
||||
// if(VList::listNeedDelete(_len))
|
||||
// {
|
||||
delete[] _tmp;
|
||||
//_tmp = NULL;
|
||||
//}
|
||||
// }
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -1998,12 +1941,8 @@ KVstore::getsubIDlistByobjIDpreID(TYPE_ENTITY_LITERAL_ID _objid, TYPE_PREDICATE_
|
|||
|
||||
//if this is a long list, then we should remove itself after copying
|
||||
//otherwise, we should not free the list memory
|
||||
//if(VList::listNeedDelete(_len))
|
||||
//{
|
||||
delete[] _tmp;
|
||||
delete[] _tmp;
|
||||
//_tmp = NULL;
|
||||
//}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -2039,11 +1978,11 @@ KVstore::getpreIDsubIDlistByobjID(TYPE_ENTITY_LITERAL_ID _objid, unsigned*& _pre
|
|||
|
||||
//if this is a long list, then we should remove itself after copying
|
||||
//otherwise, we should not free the list memory
|
||||
//if(VList::listNeedDelete(_len))
|
||||
//{
|
||||
// if(VList::listNeedDelete(_len))
|
||||
// {
|
||||
delete[] _tmp;
|
||||
//_tmp = NULL;
|
||||
//}
|
||||
// }
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -2159,11 +2098,11 @@ KVstore::getsubIDlistBypreID(TYPE_PREDICATE_ID _preid, unsigned*& _subidlist, un
|
|||
|
||||
//if this is a long list, then we should remove itself after copying
|
||||
//otherwise, we should not free the list memory
|
||||
//if(VList::listNeedDelete(_len))
|
||||
//{
|
||||
// if(VList::listNeedDelete(_len))
|
||||
// {
|
||||
delete[] _tmp;
|
||||
//_tmp = NULL;
|
||||
//}
|
||||
// }
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -2190,11 +2129,11 @@ KVstore::getobjIDlistBypreID(TYPE_PREDICATE_ID _preid, unsigned*& _objidlist, un
|
|||
|
||||
//if this is a long list, then we should remove itself after copying
|
||||
//otherwise, we should not free the list memory
|
||||
//if(VList::listNeedDelete(_len))
|
||||
//{
|
||||
// if(VList::listNeedDelete(_len))
|
||||
// {
|
||||
delete[] _tmp;
|
||||
//_tmp = NULL;
|
||||
//}
|
||||
// }
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -2230,14 +2169,14 @@ KVstore::getsubIDobjIDlistBypreID(TYPE_PREDICATE_ID _preid, unsigned*& _subid_ob
|
|||
|
||||
//if this is a long list, then we should remove itself after copying
|
||||
//otherwise, we should not free the list memory
|
||||
//if(VList::listNeedDelete(_len))
|
||||
//{
|
||||
// if(VList::listNeedDelete(_len))
|
||||
// {
|
||||
#ifdef DEBUG_KVSTORE
|
||||
cout<<"this is a vlist"<<endl;
|
||||
#endif
|
||||
delete[] _tmp;
|
||||
//_tmp = NULL;
|
||||
//}
|
||||
// }
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -2304,11 +2243,11 @@ KVstore::getpreIDlistBysubIDobjID(TYPE_ENTITY_LITERAL_ID _subid, TYPE_ENTITY_LIT
|
|||
|
||||
//if this is a long list, then we should remove itself after copying
|
||||
//otherwise, we should not free the list memory
|
||||
//if(VList::listNeedDelete(_len))
|
||||
//{
|
||||
// if(VList::listNeedDelete(_len))
|
||||
// {
|
||||
delete[] _tmp;
|
||||
//_tmp = NULL;
|
||||
//}
|
||||
// }
|
||||
|
||||
if (_list_len == 0) {
|
||||
_preidlist = NULL;
|
||||
|
@ -2567,8 +2506,8 @@ string KVstore::s_entity2id = "s_entity2id";
|
|||
string KVstore::s_id2entity = "s_id2entity";
|
||||
unsigned short KVstore::buffer_entity2id_build = 8;
|
||||
unsigned short KVstore::buffer_id2entity_build = 8;
|
||||
unsigned short KVstore::buffer_entity2id_query = 4;
|
||||
unsigned short KVstore::buffer_id2entity_query = 2;
|
||||
unsigned short KVstore::buffer_entity2id_query = 2;
|
||||
unsigned short KVstore::buffer_id2entity_query = 1;
|
||||
|
||||
string KVstore::s_predicate2id = "s_predicate2id";
|
||||
string KVstore::s_id2predicate = "s_id2predicate";
|
||||
|
@ -2581,8 +2520,8 @@ string KVstore::s_literal2id = "s_literal2id";
|
|||
string KVstore::s_id2literal = "s_id2literal";
|
||||
unsigned short KVstore::buffer_literal2id_build = 8;
|
||||
unsigned short KVstore::buffer_id2literal_build = 8;
|
||||
unsigned short KVstore::buffer_literal2id_query = 4;
|
||||
unsigned short KVstore::buffer_id2literal_query = 2;
|
||||
unsigned short KVstore::buffer_literal2id_query = 2;
|
||||
unsigned short KVstore::buffer_id2literal_query = 1;
|
||||
|
||||
string KVstore::s_sID2values = "s_sID2values";
|
||||
string KVstore::s_oID2values = "s_oID2values";
|
||||
|
|
Loading…
Reference in New Issue