Skip to content

Commit

Permalink
Merge pull request #35 from Algunenano/leaks
Browse files Browse the repository at this point in the history
 Leaks
  • Loading branch information
Raúl Marín authored May 23, 2019
2 parents 9f0a720 + 925fe7f commit f8f2cda
Show file tree
Hide file tree
Showing 37 changed files with 395 additions and 300 deletions.
10 changes: 10 additions & 0 deletions CHANGELOG.carto.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
# CARTO node-mapnik changelog

## 3.6.2-carto.16

**Release date**: 2019-XX-XX

Changes:
- Silence GCC warnings around uv_after_work_cb functions.
- Tests: Avoid Buffer() constructor.
- Avoid dangling references when an error happenned before an async task.
- mapnik_image: Avoid throwing in callbacks as it leaks resources.

## 3.6.2-carto.15

**Release date**: 2019-05-20
Expand Down
4 changes: 2 additions & 2 deletions src/blend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -418,7 +418,7 @@ void Work_Blend(uv_work_t* req)
Blend_Encode(target, baton, alpha);
}

void Work_AfterBlend(uv_work_t* req) {
void EIO_AfterBlend(uv_work_t* req, int) {
Nan::HandleScope scope;
BlendBaton* baton = static_cast<BlendBaton*>(req->data);
Nan::AsyncResource async_resource(__func__);
Expand Down Expand Up @@ -674,7 +674,7 @@ NAN_METHOD(Blend) {
baton->images.push_back(image);
}

uv_queue_work(uv_default_loop(), &(baton.release())->request, Work_Blend, (uv_after_work_cb)Work_AfterBlend);
uv_queue_work(uv_default_loop(), &(baton.release())->request, Work_Blend, (uv_after_work_cb)EIO_AfterBlend);

return;
}
Expand Down
1 change: 1 addition & 0 deletions src/blend.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wunused-parameter"
#pragma GCC diagnostic ignored "-Wshadow"
#pragma GCC diagnostic ignored "-Wcast-function-type"
#include <nan.h>
#pragma GCC diagnostic pop

Expand Down
1 change: 1 addition & 0 deletions src/ds_emitter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wunused-parameter"
#pragma GCC diagnostic ignored "-Wshadow"
#pragma GCC diagnostic ignored "-Wcast-function-type"
#include <nan.h>
#pragma GCC diagnostic pop

Expand Down
1 change: 1 addition & 0 deletions src/mapnik_cairo_surface.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wunused-parameter"
#pragma GCC diagnostic ignored "-Wshadow"
#pragma GCC diagnostic ignored "-Wcast-function-type"
#include <nan.h>
#pragma GCC diagnostic pop

Expand Down
1 change: 1 addition & 0 deletions src/mapnik_color.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wunused-parameter"
#pragma GCC diagnostic ignored "-Wshadow"
#pragma GCC diagnostic ignored "-Wcast-function-type"
#include <nan.h>
#pragma GCC diagnostic pop

Expand Down
1 change: 1 addition & 0 deletions src/mapnik_datasource.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wunused-parameter"
#pragma GCC diagnostic ignored "-Wshadow"
#pragma GCC diagnostic ignored "-Wcast-function-type"
#include <nan.h>
#pragma GCC diagnostic pop

Expand Down
1 change: 1 addition & 0 deletions src/mapnik_expression.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wunused-parameter"
#pragma GCC diagnostic ignored "-Wshadow"
#pragma GCC diagnostic ignored "-Wcast-function-type"
#include <nan.h>
#pragma GCC diagnostic pop

Expand Down
1 change: 1 addition & 0 deletions src/mapnik_feature.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wunused-parameter"
#pragma GCC diagnostic ignored "-Wshadow"
#pragma GCC diagnostic ignored "-Wcast-function-type"
#include <nan.h>
#pragma GCC diagnostic pop

Expand Down
1 change: 1 addition & 0 deletions src/mapnik_featureset.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wunused-parameter"
#pragma GCC diagnostic ignored "-Wshadow"
#pragma GCC diagnostic ignored "-Wcast-function-type"
#include <nan.h>
#pragma GCC diagnostic pop

Expand Down
8 changes: 4 additions & 4 deletions src/mapnik_geometry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -244,8 +244,8 @@ NAN_METHOD(Geometry::toJSON)
}
v8::Local<v8::Value> callback = info[info.Length()-1];
closure->cb.Reset(callback.As<v8::Function>());
uv_queue_work(uv_default_loop(), &closure->request, to_json, (uv_after_work_cb)after_to_json);
closure->g->Ref();
uv_queue_work(uv_default_loop(), &closure->request, to_json, (uv_after_work_cb)EIO_After_to_json);
closure->g->_ref();
return;
}

Expand Down Expand Up @@ -292,7 +292,7 @@ void Geometry::to_json(uv_work_t* req)
}
}

void Geometry::after_to_json(uv_work_t* req)
void Geometry::EIO_After_to_json(uv_work_t* req, int)
{
Nan::HandleScope scope;
to_json_baton *closure = static_cast<to_json_baton *>(req->data);
Expand All @@ -311,7 +311,7 @@ void Geometry::after_to_json(uv_work_t* req)
v8::Local<v8::Value> argv[2] = { Nan::Null(), Nan::New<v8::String>(closure->result).ToLocalChecked() };
async_resource.runInAsyncScope(Nan::GetCurrentContext()->Global(), Nan::New(closure->cb), 2, argv);
}
closure->g->Unref();
closure->g->_unref();
if (closure->tr) {
closure->tr->_unref();
}
Expand Down
6 changes: 5 additions & 1 deletion src/mapnik_geometry.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wunused-parameter"
#pragma GCC diagnostic ignored "-Wshadow"
#pragma GCC diagnostic ignored "-Wcast-function-type"
#include <nan.h>
#pragma GCC diagnostic pop

Expand All @@ -26,8 +27,11 @@ class Geometry: public Nan::ObjectWrap {
static NAN_METHOD(toJSON);
static NAN_METHOD(toJSONSync);
static void to_json(uv_work_t* req);
static void after_to_json(uv_work_t* req);
static void EIO_After_to_json(uv_work_t* req, int);
Geometry(mapnik::feature_ptr f);

void _ref() { Ref(); }
void _unref() { Unref(); }
private:
~Geometry();
mapnik::feature_ptr feat_;
Expand Down
12 changes: 6 additions & 6 deletions src/mapnik_grid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ NAN_METHOD(Grid::clear)
closure->error = false;
closure->cb.Reset(callback.As<v8::Function>());
uv_queue_work(uv_default_loop(), &closure->request, EIO_Clear, (uv_after_work_cb)EIO_AfterClear);
g->Ref();
g->_ref();
return;
}

Expand All @@ -184,7 +184,7 @@ void Grid::EIO_Clear(uv_work_t* req)
}
}

void Grid::EIO_AfterClear(uv_work_t* req)
void Grid::EIO_AfterClear(uv_work_t* req, int)
{
Nan::HandleScope scope;
Nan::AsyncResource async_resource(__func__);
Expand All @@ -204,7 +204,7 @@ void Grid::EIO_AfterClear(uv_work_t* req)
v8::Local<v8::Value> argv[2] = { Nan::Null(), closure->g->handle() };
async_resource.runInAsyncScope(Nan::GetCurrentContext()->Global(), Nan::New(closure->cb), 2, argv);
}
closure->g->Unref();
closure->g->_unref();
closure->cb.Reset();
delete closure;
}
Expand Down Expand Up @@ -522,7 +522,7 @@ NAN_METHOD(Grid::encode)
closure->cb.Reset(callback.As<v8::Function>());
// todo - reserve lines size?
uv_queue_work(uv_default_loop(), &closure->request, EIO_Encode, (uv_after_work_cb)EIO_AfterEncode);
g->Ref();
g->_ref();
return;
}

Expand All @@ -548,7 +548,7 @@ void Grid::EIO_Encode(uv_work_t* req)
}
}

void Grid::EIO_AfterEncode(uv_work_t* req)
void Grid::EIO_AfterEncode(uv_work_t* req, int)
{
Nan::HandleScope scope;
Nan::AsyncResource async_resource(__func__);
Expand Down Expand Up @@ -602,7 +602,7 @@ void Grid::EIO_AfterEncode(uv_work_t* req)
async_resource.runInAsyncScope(Nan::GetCurrentContext()->Global(), Nan::New(closure->cb), 2, argv);
}

closure->g->Unref();
closure->g->_unref();
closure->cb.Reset();
delete closure;
}
Expand Down
5 changes: 3 additions & 2 deletions src/mapnik_grid.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wunused-parameter"
#pragma GCC diagnostic ignored "-Wshadow"
#pragma GCC diagnostic ignored "-Wcast-function-type"
#include <nan.h>
#pragma GCC diagnostic pop

Expand All @@ -25,7 +26,7 @@ class Grid: public Nan::ObjectWrap {
static NAN_METHOD(encodeSync);
static NAN_METHOD(encode);
static void EIO_Encode(uv_work_t* req);
static void EIO_AfterEncode(uv_work_t* req);
static void EIO_AfterEncode(uv_work_t* req, int);

static NAN_METHOD(addField);
static NAN_METHOD(fields);
Expand All @@ -37,7 +38,7 @@ class Grid: public Nan::ObjectWrap {
static NAN_METHOD(clearSync);
static NAN_METHOD(clear);
static void EIO_Clear(uv_work_t* req);
static void EIO_AfterClear(uv_work_t* req);
static void EIO_AfterClear(uv_work_t* req, int);

static NAN_GETTER(get_key);
static NAN_SETTER(set_key);
Expand Down
12 changes: 6 additions & 6 deletions src/mapnik_grid_view.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ NAN_METHOD(GridView::isSolid)
closure->error = false;
closure->cb.Reset(callback.As<v8::Function>());
uv_queue_work(uv_default_loop(), &closure->request, EIO_IsSolid, (uv_after_work_cb)EIO_AfterIsSolid);
g->Ref();
g->_ref();
return;
}
void GridView::EIO_IsSolid(uv_work_t* req)
Expand Down Expand Up @@ -183,7 +183,7 @@ void GridView::EIO_IsSolid(uv_work_t* req)
}
}

void GridView::EIO_AfterIsSolid(uv_work_t* req)
void GridView::EIO_AfterIsSolid(uv_work_t* req, int)
{
Nan::HandleScope scope;
Nan::AsyncResource async_resource(__func__);
Expand All @@ -210,7 +210,7 @@ void GridView::EIO_AfterIsSolid(uv_work_t* req)
async_resource.runInAsyncScope(Nan::GetCurrentContext()->Global(), Nan::New(closure->cb), 2, argv);
}
}
closure->g->Unref();
closure->g->_unref();
closure->cb.Reset();
delete closure;
}
Expand Down Expand Up @@ -455,7 +455,7 @@ NAN_METHOD(GridView::encode)
closure->add_features = add_features;
closure->cb.Reset(callback);
uv_queue_work(uv_default_loop(), &closure->request, EIO_Encode, (uv_after_work_cb)EIO_AfterEncode);
g->Ref();
g->_ref();
return;
}

Expand All @@ -482,7 +482,7 @@ void GridView::EIO_Encode(uv_work_t* req)
}
}

void GridView::EIO_AfterEncode(uv_work_t* req)
void GridView::EIO_AfterEncode(uv_work_t* req, int)
{
Nan::HandleScope scope;
Nan::AsyncResource async_resource(__func__);
Expand Down Expand Up @@ -534,7 +534,7 @@ void GridView::EIO_AfterEncode(uv_work_t* req)
async_resource.runInAsyncScope(Nan::GetCurrentContext()->Global(), Nan::New(closure->cb), 2, argv);
}

closure->g->Unref();
closure->g->_unref();
closure->cb.Reset();
delete closure;
}
Expand Down
8 changes: 6 additions & 2 deletions src/mapnik_grid_view.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wunused-parameter"
#pragma GCC diagnostic ignored "-Wshadow"
#pragma GCC diagnostic ignored "-Wcast-function-type"
#include <nan.h>
#pragma GCC diagnostic pop

Expand All @@ -29,20 +30,23 @@ class GridView: public Nan::ObjectWrap {
static NAN_METHOD(encode);
static NAN_METHOD(fields);
static void EIO_Encode(uv_work_t* req);
static void EIO_AfterEncode(uv_work_t* req);
static void EIO_AfterEncode(uv_work_t* req, int);

static NAN_METHOD(width);
static NAN_METHOD(height);
static NAN_METHOD(isSolid);
static void EIO_IsSolid(uv_work_t* req);
static void EIO_AfterIsSolid(uv_work_t* req);
static void EIO_AfterIsSolid(uv_work_t* req, int);
static v8::Local<v8::Value> _isSolidSync(Nan::NAN_METHOD_ARGS_TYPE info);
static NAN_METHOD(isSolidSync);
static NAN_METHOD(getPixel);

GridView(Grid * JSGrid);
inline grid_view_ptr get() { return this_; }

void _ref() { Ref(); }
void _unref() { Unref(); }

private:
~GridView();
grid_view_ptr this_;
Expand Down
Loading

0 comments on commit f8f2cda

Please sign in to comment.