diff --git a/GeoIndex/GeoIndex.c b/GeoIndex/GeoIndex.c index 92eead461a..7aae9d4caa 100644 --- a/GeoIndex/GeoIndex.c +++ b/GeoIndex/GeoIndex.c @@ -785,6 +785,11 @@ GeoResults * GeoResultsCons(int alloc) GeoResults * gres; int * sa; double * dd; + + if (alloc <= 0) { + return NULL; + } + gres=malloc(sizeof(GeoResults)); sa=malloc(alloc*sizeof(int)); dd=malloc(alloc*sizeof(double)); @@ -939,7 +944,15 @@ GeoCoordinates * GeoAnswers (GeoIx * gix, GeoResults * gr) GeoCoordinate * gc; int i,j,slot; double mole; - ans = malloc(sizeof(GeoCoordinates));; + + if (gr->pointsct == 0) { + free(gr->slot); + free(gr->snmd); + free(gr); + return NULL; + } + + ans = malloc(sizeof(GeoCoordinates)); gc = malloc(gr->pointsct * sizeof(GeoCoordinate)); if( (ans==NULL) || (gc==NULL) ) { @@ -970,6 +983,7 @@ GeoCoordinates * GeoAnswers (GeoIx * gix, GeoResults * gr) j++; } ans->distances = gr->snmd; + /* gr->snmd must not be freed, it is handed over to ans */ free(gr->slot); free(gr); return ans; diff --git a/V8/v8-vocbase.cpp b/V8/v8-vocbase.cpp index be6920cc0a..b0d0ea3adf 100644 --- a/V8/v8-vocbase.cpp +++ b/V8/v8-vocbase.cpp @@ -380,6 +380,7 @@ static void StoreGeoResult (TRI_vocbase_col_t const* collection, n = cors->length; if (n == 0) { + GeoIndex_CoordinatesFree(cors); return; } @@ -2037,6 +2038,7 @@ static v8::Handle JS_NearQuery (v8::Arguments const& argv) { // ............................................................................. ReleaseCollection(collection); + return scope.Close(result); }