From 21fa3ed61679968706af9c0eb61e5e6462bcc7c8 Mon Sep 17 00:00:00 2001 From: Jan Steemann Date: Tue, 4 Dec 2012 21:21:26 +0100 Subject: [PATCH] small stuff, oom handling etc. --- arangod/BitIndexes/bitarray.c | 11 ++++++++--- arangod/SkipLists/skiplist.c | 4 ++-- arangod/VocBase/index.c | 14 +++++++++++++- arangod/VocBase/primary-collection.c | 4 ++-- arangod/VocBase/voc-shaper.c | 2 +- lib/HttpServer/HttpHandler.cpp | 4 ++-- 6 files changed, 28 insertions(+), 11 deletions(-) diff --git a/arangod/BitIndexes/bitarray.c b/arangod/BitIndexes/bitarray.c index a97810a27a..7d108e2e48 100755 --- a/arangod/BitIndexes/bitarray.c +++ b/arangod/BitIndexes/bitarray.c @@ -277,12 +277,17 @@ int TRI_FreeBitarray(TRI_bitarray_t* ba) { //////////////////////////////////////////////////////////////////////////////// int TRI_InsertBitMaskElementBitarray(TRI_bitarray_t* ba, TRI_bitarray_mask_t* mask, void* element) { - // TODO: ba is dereferenced in the following line, but 4 lines later it is check for NULL. This is illogical - MasterTable_t* mt = (MasterTable_t*)(ba->_masterTable); + MasterTable_t* mt; TRI_master_table_position_t position; int result; + + if (ba == NULL || mask == NULL || element == NULL) { + return TRI_ERROR_INTERNAL; + } - if (ba == NULL || mask == NULL || element == NULL || mt == NULL) { + mt = (MasterTable_t*)(ba->_masterTable); + + if (mt == NULL) { assert(NULL); return TRI_ERROR_INTERNAL; } diff --git a/arangod/SkipLists/skiplist.c b/arangod/SkipLists/skiplist.c index 58341c3047..2fc04d5281 100755 --- a/arangod/SkipLists/skiplist.c +++ b/arangod/SkipLists/skiplist.c @@ -429,8 +429,8 @@ void TRI_InitSkipList (TRI_skiplist_t* skiplist, size_t elementSize, // .......................................................................... growResult = GrowNodeHeight(&(skiplist->_base._startNode), 2); // may fail growResult = growResult && GrowNodeHeight(&(skiplist->_base._endNode), 2); // may fail - if (!growResult) { - // todo: undo growth by cutting down the node height + if (! growResult) { + // TODO: undo growth by cutting down the node height return; } diff --git a/arangod/VocBase/index.c b/arangod/VocBase/index.c index a9c71ed51b..f9069cc1bc 100644 --- a/arangod/VocBase/index.c +++ b/arangod/VocBase/index.c @@ -1886,6 +1886,11 @@ static int InsertHashIndex (TRI_index_t* idx, TRI_doc_mptr_t const* doc) { // ............................................................................. hashElement.fields = TRI_Allocate(TRI_CORE_MEM_ZONE, sizeof(TRI_shaped_json_t) * hashIndex->_paths._length, false); + if (hashElement.fields == NULL) { + LOG_ERROR("out of memory in hashindex"); + return TRI_set_errno(TRI_ERROR_OUT_OF_MEMORY); + } + res = HashIndexHelper(hashIndex, &hashElement, doc, NULL); @@ -1962,6 +1967,10 @@ static int RemoveHashIndex (TRI_index_t* idx, TRI_doc_mptr_t const* doc) { // ............................................................................. hashElement.fields = TRI_Allocate(TRI_CORE_MEM_ZONE, sizeof(TRI_shaped_json_t) * hashIndex->_paths._length, false); + if (hashElement.fields == NULL) { + LOG_ERROR("out of memory in hashindex"); + return TRI_set_errno(TRI_ERROR_OUT_OF_MEMORY); + } // ............................................................................. // Fill the json field list from the document @@ -2056,6 +2065,10 @@ static int UpdateHashIndex (TRI_index_t* idx, // ............................................................................. hashElement.fields = TRI_Allocate(TRI_CORE_MEM_ZONE, sizeof(TRI_shaped_json_t) * hashIndex->_paths._length, false); + if (hashElement.fields == NULL) { + LOG_ERROR("out of memory in hashindex"); + return TRI_set_errno(TRI_ERROR_OUT_OF_MEMORY); + } // ............................................................................. // Update for unique hash index @@ -4357,7 +4370,6 @@ static int UpdateFulltextIndex (TRI_index_t* idx, const TRI_doc_mptr_t* newDoc, const TRI_shaped_json_t* oldDoc) { - // TODO union { void* p; void const* c; } cnv; TRI_fulltext_index_t* fulltextIndex; int res; diff --git a/arangod/VocBase/primary-collection.c b/arangod/VocBase/primary-collection.c index 77d009263c..fded31763c 100644 --- a/arangod/VocBase/primary-collection.c +++ b/arangod/VocBase/primary-collection.c @@ -454,8 +454,8 @@ int TRI_InitPrimaryCollection (TRI_primary_collection_t* primary, TRI_InitReadWriteLock(&primary->_lock); - // init key generator. TODO: make this configurable - res = TRI_CreateKeyGenerator(NULL, primary); + // init key generator + res = TRI_CreateKeyGenerator(primary->base._info._options, primary); return res; } diff --git a/arangod/VocBase/voc-shaper.c b/arangod/VocBase/voc-shaper.c index a635f63c92..a46767d70c 100644 --- a/arangod/VocBase/voc-shaper.c +++ b/arangod/VocBase/voc-shaper.c @@ -1099,7 +1099,7 @@ int TRI_CloseVocShaper (TRI_shaper_t* s) { err = TRI_CloseShapeCollection(shaper->_collection); if (err != TRI_ERROR_NO_ERROR) { - LOG_ERROR("cannot close shape collection of shaper, error %lu", (unsigned long) err); + LOG_ERROR("cannot close shape collection of shaper, error %d", (int) err); } // TODO free the accessors diff --git a/lib/HttpServer/HttpHandler.cpp b/lib/HttpServer/HttpHandler.cpp index 43c05b59a7..1db2505a52 100644 --- a/lib/HttpServer/HttpHandler.cpp +++ b/lib/HttpServer/HttpHandler.cpp @@ -110,7 +110,7 @@ HttpResponse* HttpHandler::getResponse () const { Job* HttpHandler::createJob (AsyncJobServer* server) { HttpServer* httpServer = dynamic_cast(server); - // stj: TODO: ugly temporary hack, must be fixed + // TODO: ugly temporary hack, must be fixed if (httpServer != 0) { return new GeneralServerJob(httpServer, this); } @@ -119,7 +119,7 @@ Job* HttpHandler::createJob (AsyncJobServer* server) { if (httpsServer != 0) { return new GeneralServerJob(httpsServer, this); } - // stj: end of hack + // end of hack LOGGER_WARNING << "cannot convert AsyncJobServer into a HttpServer"; return 0;