Skip to content

Commit

Permalink
Fixed memory leak when creating spatial reference objects (Fixes #273)
Browse files Browse the repository at this point in the history
  • Loading branch information
brandonreavis committed Sep 30, 2020
1 parent a1c99d5 commit f6e382c
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/gdal_spatial_reference.cpp
Expand Up @@ -175,7 +175,11 @@ Local<Value> SpatialReference::New(OGRSpatialReference *raw, bool owned)
Local<Value> ext = Nan::New<External>(wrapped);
Local<Object> obj = Nan::NewInstance(Nan::GetFunction(Nan::New(SpatialReference::constructor)).ToLocalChecked(), 1, &ext).ToLocalChecked();

cache.add(cloned_srs, raw, obj);
if (owned) {
raw->Release(); // decrement reference counter and delete if 0
} else {
cache.add(cloned_srs, raw, obj);
}

return scope.Escape(obj);
}
Expand Down Expand Up @@ -329,7 +333,7 @@ NAN_METHOD(SpatialReference::clone)
{
Nan::HandleScope scope;
SpatialReference *srs = Nan::ObjectWrap::Unwrap<SpatialReference>(info.This());
info.GetReturnValue().Set(SpatialReference::New(srs->this_->Clone()));
info.GetReturnValue().Set(SpatialReference::New(srs->this_->Clone(), true));
}

/**
Expand All @@ -342,7 +346,7 @@ NAN_METHOD(SpatialReference::cloneGeogCS)
{
Nan::HandleScope scope;
SpatialReference *srs = Nan::ObjectWrap::Unwrap<SpatialReference>(info.This());
info.GetReturnValue().Set(SpatialReference::New(srs->this_->CloneGeogCS()));
info.GetReturnValue().Set(SpatialReference::New(srs->this_->CloneGeogCS(), true));
}

/**
Expand Down

0 comments on commit f6e382c

Please sign in to comment.