1
0
Fork 0

fixed memleaks

This commit is contained in:
Jan Steemann 2012-04-04 17:02:11 +02:00
parent e23e56d4d5
commit 8401e115bb
5 changed files with 70 additions and 9 deletions

View File

@ -217,6 +217,7 @@ static TRI_shape_pid_t FindNameAttributePath (TRI_shaper_t* shaper, char const*
// split path into attribute pieces
count = 0;
aids = TRI_Allocate(len * sizeof(TRI_shape_aid_t));
/* TODO FIXME: memory allocation might fail */
buffer = ptr = TRI_DuplicateString2(name, len);
end = buffer + len + 1;
@ -239,6 +240,7 @@ static TRI_shape_pid_t FindNameAttributePath (TRI_shaper_t* shaper, char const*
// create element
total = sizeof(TRI_shape_path_t) + (len + 1) + (count * sizeof(TRI_shape_aid_t));
result = TRI_Allocate(total);
/* TODO FIXME: memory allocation might fail */
result->_pid = shaper->_nextPid++;
result->_nameLength = len + 1;
@ -331,6 +333,7 @@ static TRI_shape_aid_t FindAttributeNameArrayShaper (TRI_shaper_t* shaper, char
n = strlen(name) + 1;
a2i = TRI_Allocate(sizeof(attribute_2_id_t) + n);
/* TODO FIXME: memory allocation might fail */
a2i->_aid = 1 + s->_attributes._length;
a2i->_size = n;
@ -479,6 +482,7 @@ TRI_shaper_t* TRI_CreateArrayShaper () {
// create the shaper
shaper = TRI_Allocate(sizeof(array_shaper_t));
/* TODO FIXME: memory allocation might fail */
TRI_InitShaper(&shaper->base);
@ -640,6 +644,19 @@ void TRI_InitShaper (TRI_shaper_t* shaper) {
////////////////////////////////////////////////////////////////////////////////
void TRI_DestroyShaper (TRI_shaper_t* shaper) {
size_t n = shaper->_attributePathsByName._nrAlloc;
size_t i;
// only free pointers in attributePathsByName
// (attributePathsByPid contains the same pointers!)
for (i = 0; i < n; ++i) {
void* data = shaper->_attributePathsByName._table[i];
if (data) {
TRI_Free(data);
}
}
TRI_DestroyAssociativeSynced(&shaper->_attributePathsByName);
TRI_DestroyAssociativeSynced(&shaper->_attributePathsByPid);
@ -656,6 +673,7 @@ bool TRI_InsertBasicTypesShaper (TRI_shaper_t* shaper) {
// NULL
shape = TRI_Allocate(sizeof(TRI_null_shape_t));
/* TODO FIXME: memory allocation might fail */
memset(shape, 0, sizeof(TRI_null_shape_t));
shape->_size = sizeof(TRI_null_shape_t);
@ -672,6 +690,7 @@ bool TRI_InsertBasicTypesShaper (TRI_shaper_t* shaper) {
// BOOLEAN
shape = TRI_Allocate(sizeof(TRI_boolean_shape_t));
/* TODO FIXME: memory allocation might fail */
memset(shape, 0, sizeof(TRI_boolean_shape_t));
shape->_size = sizeof(TRI_boolean_shape_t);
@ -688,6 +707,7 @@ bool TRI_InsertBasicTypesShaper (TRI_shaper_t* shaper) {
// NUMBER
shape = TRI_Allocate(sizeof(TRI_number_shape_t));
/* TODO FIXME: memory allocation might fail */
memset(shape, 0, sizeof(TRI_number_shape_t));
shape->_size = sizeof(TRI_number_shape_t);
@ -704,6 +724,7 @@ bool TRI_InsertBasicTypesShaper (TRI_shaper_t* shaper) {
// SHORT STRING
shape = TRI_Allocate(sizeof(TRI_short_string_shape_t));
/* TODO FIXME: memory allocation might fail */
memset(shape, 0, sizeof(TRI_short_string_shape_t));
shape->_size = sizeof(TRI_short_string_shape_t);
@ -720,6 +741,7 @@ bool TRI_InsertBasicTypesShaper (TRI_shaper_t* shaper) {
// LONG STRING
shape = TRI_Allocate(sizeof(TRI_long_string_shape_t));
/* TODO FIXME: memory allocation might fail */
memset(shape, 0, sizeof(TRI_long_string_shape_t));
shape->_size = sizeof(TRI_long_string_shape_t);
@ -736,6 +758,7 @@ bool TRI_InsertBasicTypesShaper (TRI_shaper_t* shaper) {
// LIST
shape = TRI_Allocate(sizeof(TRI_list_shape_t));
/* TODO FIXME: memory allocation might fail */
memset(shape, 0, sizeof(TRI_list_shape_t));
shape->_size = sizeof(TRI_list_shape_t);

View File

@ -841,7 +841,8 @@ static void* SkiplistPrevsIterationCallback(TRI_skiplist_iterator_t* iterator, i
void SkiplistIndexDestroy(SkiplistIndex* slIndex) {
if (slIndex == NULL) {
return;
}
}
if (slIndex->unique) {
TRI_FreeSkipList(slIndex->skiplist.uniqueSkiplist);
slIndex->skiplist.uniqueSkiplist = NULL;

View File

@ -557,6 +557,10 @@ static v8::Handle<v8::Value> EnsureHashSkipListIndex (string const& cmd,
// .............................................................................
TRI_json_t* json = idx->json(idx, collection->_collection);
if (!json) {
return scope.Close(v8::ThrowException(v8::String::New("out of memory")));
}
v8::Handle<v8::Value> index = TRI_ObjectJson(json);
if (index->IsObject()) {
@ -564,6 +568,8 @@ static v8::Handle<v8::Value> EnsureHashSkipListIndex (string const& cmd,
}
ReleaseCollection(collection);
TRI_FreeJson(json);
return scope.Close(index);
}
@ -3557,6 +3563,10 @@ static v8::Handle<v8::Value> JS_EnsureGeoIndexVocbaseCol (v8::Arguments const& a
}
TRI_json_t* json = idx->json(idx, collection->_collection);
if (!json) {
return scope.Close(v8::ThrowException(v8::String::New("out of memory")));
}
v8::Handle<v8::Value> index = TRI_ObjectJson(json);
if (index->IsObject()) {
@ -3564,6 +3574,8 @@ static v8::Handle<v8::Value> JS_EnsureGeoIndexVocbaseCol (v8::Arguments const& a
}
ReleaseCollection(collection);
TRI_FreeJson(json);
return scope.Close(index);
}
@ -3727,6 +3739,9 @@ static v8::Handle<v8::Value> JS_GetIndexesVocbaseCol (v8::Arguments const& argv)
// get a list of indexes
TRI_vector_pointer_t* indexes = TRI_IndexesSimCollection(sim);
if (!indexes) {
return scope.Close(v8::ThrowException(v8::String::New("out of memory")));
}
v8::Handle<v8::Array> result = v8::Array::New();
@ -3734,11 +3749,16 @@ static v8::Handle<v8::Value> JS_GetIndexesVocbaseCol (v8::Arguments const& argv)
for (uint32_t i = 0; i < n; ++i) {
TRI_json_t* idx = (TRI_json_t*) indexes->_buffer[i];
result->Set(i, TRI_ObjectJson(idx));
if (idx) {
result->Set(i, TRI_ObjectJson(idx));
TRI_FreeJson(idx);
}
}
ReleaseCollection(collection);
TRI_FreeVectorPointer(indexes);
return scope.Close(result);
}

View File

@ -58,6 +58,8 @@
void TRI_FreeIndex (TRI_index_t* const idx) {
assert(idx);
LOG_TRACE("freeing index");
switch (idx->_type) {
case TRI_IDX_TYPE_GEO_INDEX:
TRI_FreeGeoIndex(idx);
@ -244,6 +246,8 @@ char const* TRI_TypeNameIndex (const TRI_index_t* const idx) {
////////////////////////////////////////////////////////////////////////////////
void TRI_DestroyPrimaryIndex (TRI_index_t* idx) {
LOG_TRACE("destroying primary index");
TRI_DestroyVectorString(&idx->_fields);
}
@ -744,9 +748,9 @@ static TRI_json_t* JsonGeoIndex2 (TRI_index_t* idx, TRI_doc_collection_t const*
TRI_PushBack3ListJson(fields, TRI_CreateStringCopyJson(latitude));
TRI_PushBack3ListJson(fields, TRI_CreateStringCopyJson(longitude));
TRI_Insert2ArrayJson(json, "id", TRI_CreateNumberJson(idx->_iid));
TRI_Insert2ArrayJson(json, "type", TRI_CreateStringCopyJson("geo"));
TRI_Insert2ArrayJson(json, "fields", fields);
TRI_Insert3ArrayJson(json, "id", TRI_CreateNumberJson(idx->_iid));
TRI_Insert3ArrayJson(json, "type", TRI_CreateStringCopyJson("geo"));
TRI_Insert3ArrayJson(json, "fields", fields);
return json;
}
@ -776,9 +780,14 @@ TRI_index_t* TRI_CreateGeoIndex (struct TRI_doc_collection_s* collection,
char* ln;
geo = TRI_Allocate(sizeof(TRI_geo_index_t));
ln = TRI_DuplicateString(locationName);
if (geo == NULL) {
TRI_set_errno(TRI_ERROR_OUT_OF_MEMORY);
return NULL;
}
if (geo == NULL || ln == NULL) {
ln = TRI_DuplicateString(locationName);
if (ln == NULL) {
TRI_Free(geo);
TRI_set_errno(TRI_ERROR_OUT_OF_MEMORY);
return NULL;
}
@ -862,6 +871,7 @@ TRI_index_t* TRI_CreateGeoIndex2 (struct TRI_doc_collection_s* collection,
void TRI_DestroyGeoIndex (TRI_index_t* idx) {
TRI_geo_index_t* geo;
LOG_TRACE("destroying geo index");
TRI_DestroyVectorString(&idx->_fields);
geo = (TRI_geo_index_t*) idx;
@ -1496,6 +1506,7 @@ TRI_index_t* TRI_CreateHashIndex (struct TRI_doc_collection_s* collection,
void TRI_DestroyHashIndex (TRI_index_t* idx) {
TRI_hash_index_t* hash;
LOG_TRACE("destroying hash index");
TRI_DestroyVectorString(&idx->_fields);
hash = (TRI_hash_index_t*) idx;
@ -2236,6 +2247,7 @@ void TRI_DestroySkiplistIndex (TRI_index_t* idx) {
return;
}
LOG_TRACE("destroying skiplist index");
TRI_DestroyVectorString(&idx->_fields);
sl = (TRI_skiplist_index_t*) idx;

View File

@ -2359,6 +2359,10 @@ TRI_vector_pointer_t* TRI_IndexesSimCollection (TRI_sim_collection_t* sim) {
size_t i;
vector = TRI_Allocate(sizeof(TRI_vector_pointer_t));
if (!vector) {
return NULL;
}
TRI_InitVectorPointer(vector);
// .............................................................................
@ -2802,6 +2806,7 @@ static TRI_index_t* CreateHashIndexSimCollection (TRI_sim_collection_t* collecti
// ...........................................................................
TRI_DestroyVector(&paths);
TRI_DestroyVectorPointer(&fields);
// ...........................................................................
// If index id given, use it otherwise use the default.
@ -2876,7 +2881,6 @@ static TRI_index_t* CreateSkiplistIndexSimCollection (TRI_sim_collection_t* coll
if (idx != NULL) {
TRI_DestroyVector(&paths);
TRI_DestroyVectorPointer(&fields);
LOG_TRACE("skiplist-index already created");
if (created != NULL) {
@ -2922,6 +2926,7 @@ static TRI_index_t* CreateSkiplistIndexSimCollection (TRI_sim_collection_t* coll
// ...........................................................................
TRI_DestroyVector(&paths);
TRI_DestroyVectorPointer(&fields);
if (created != NULL) {
*created = true;