Skip to content

Commit

Permalink
Fixed NanCString is deprecated in submodule cpp code
Browse files Browse the repository at this point in the history
  • Loading branch information
kuno committed May 7, 2015
1 parent 7ffd87c commit 6feda69
Show file tree
Hide file tree
Showing 10 changed files with 23 additions and 55 deletions.
2 changes: 1 addition & 1 deletion lib/city6.js
Expand Up @@ -27,7 +27,7 @@ module.exports = City6;
* @param {Object} options
*/
function City6(file, options) {
this.types = ['city_v6'];
this.types = ['city_v6', 'city'];
this.options = options ? (isObject(options) ? options : {cache: !!options})
: ({cache: true});
//
Expand Down
8 changes: 2 additions & 6 deletions src/city.cc
Expand Up @@ -63,13 +63,9 @@ NAN_METHOD(City::lookupSync) {
City *c = ObjectWrap::Unwrap<City>(args.This());

Local<Object> data = NanNew<Object>();
Local<String> host_str = args[0]->ToString();
size_t size = host_str->Length() + 1;
char host_cstr[size];
size_t bc;
NanCString(args[0], &bc, host_cstr, size);
static NanUtf8String *host_cstr = new NanUtf8String(args[0]);

uint32_t ipnum = _GeoIP_lookupaddress(host_cstr);
uint32_t ipnum = _GeoIP_lookupaddress(**host_cstr);

This comment has been minimized.

Copy link
@kkoopa

kkoopa May 7, 2015

Collaborator

You never delete the host_cstr, leading to a leak. You could add a delete host_cstr; after this line, but better would be to delete line 66 and change this to uint32_t ipnum = _GeoIP_lookupaddress(*NanUtf8String(args[0])); Now the string buffer will get freed automatically as soon as _GeoIP_lookupaddress is done. The same applies to all other changes in this commit.


//printf("Ip is %s.\n", host_cstr);
//printf("Ipnum is %d.", ipnum);
Expand Down
8 changes: 2 additions & 6 deletions src/city6.cc
Expand Up @@ -63,14 +63,10 @@ NAN_METHOD(City6::lookupSync) {
NanScope();

Local<Object> data = NanNew<Object>();
Local<String> host_str = args[0]->ToString();
size_t size = host_str->Length() + 1;
char host_cstr[size];
size_t bc;
NanCString(args[0], &bc, host_cstr, size);
City6 *c = ObjectWrap::Unwrap<City6>(args.This());

geoipv6_t ipnum_v6 = _GeoIP_lookupaddress_v6(host_cstr);
static NanUtf8String *host_cstr = new NanUtf8String(args[0]);
geoipv6_t ipnum_v6 = _GeoIP_lookupaddress_v6(**host_cstr);

if (__GEOIP_V6_IS_NULL(ipnum_v6)) {
NanReturnValue(NanNull());
Expand Down
10 changes: 3 additions & 7 deletions src/country.cc
Expand Up @@ -65,13 +65,9 @@ NAN_METHOD(Country::lookupSync) {
Country *c = ObjectWrap::Unwrap<Country>(args.This());

Local<Object> data = NanNew<Object>();
Local<String> host_str = args[0]->ToString();
size_t size = host_str->Length() + 1;
char host_cstr[size];
size_t bc;
NanCString(args[0], &bc, host_cstr, size);

uint32_t ipnum = _GeoIP_lookupaddress(host_cstr);

static NanUtf8String *host_cstr = new NanUtf8String(args[0]);
uint32_t ipnum = _GeoIP_lookupaddress(**host_cstr);

if (ipnum <= 0) {
NanReturnValue(NanNull());
Expand Down
9 changes: 2 additions & 7 deletions src/country6.cc
Expand Up @@ -69,14 +69,9 @@ NAN_METHOD(Country6::lookupSync) {
}

Local<Object> data = NanNew<Object>();
Local<String> host_str = args[0]->ToString();
size_t size = host_str->Length() + 1;
char host_cstr[size];
size_t bc;

NanCString(args[0], &bc, host_cstr, size);

geoipv6_t ipnum_v6 = _GeoIP_lookupaddress_v6(host_cstr);
static NanUtf8String *host_cstr = new NanUtf8String(args[0]);
geoipv6_t ipnum_v6 = _GeoIP_lookupaddress_v6(**host_cstr);

if (__GEOIP_V6_IS_NULL(ipnum_v6)) {
NanReturnValue(NanNull());
Expand Down
10 changes: 3 additions & 7 deletions src/netspeed.cc
Expand Up @@ -65,13 +65,9 @@ NAN_METHOD(NetSpeed::lookupSync) {
NetSpeed *n = ObjectWrap::Unwrap<NetSpeed>(args.This());

Local<Value> data = NanNew(NanNull());
Local<String> host_str = args[0]->ToString();
size_t size = host_str->Length() + 1;
char host_cstr[size];
size_t bc;
NanCString(args[0], &bc, host_cstr, size);

uint32_t ipnum = _GeoIP_lookupaddress(host_cstr);

static NanUtf8String *host_cstr = new NanUtf8String(args[0]);
uint32_t ipnum = _GeoIP_lookupaddress(**host_cstr);

if (ipnum <= 0) {
NanReturnValue(NanNull());
Expand Down
13 changes: 5 additions & 8 deletions src/netspeedcell.cc
Expand Up @@ -63,17 +63,14 @@ NAN_METHOD(NetSpeedCell::lookupSync) {
NetSpeedCell *n = ObjectWrap::Unwrap<NetSpeedCell>(args.This());

Local<Value> data = NanNew(NanNull());
Local<String> host_str = args[0]->ToString();
size_t size = host_str->Length() + 1;
char host_cstr[size];
size_t bc;
NanCString(args[0], &bc, host_cstr, size);

char *speed = GeoIP_name_by_addr(n->db, host_cstr);
static NanUtf8String *host_cstr = new NanUtf8String(args[0]);

char *speed = GeoIP_name_by_addr(n->db, **host_cstr);

if (!speed) {
data = NanNew<String>("Unknown");
}
else {
} else {
data = NanNew<String>(speed);
}

Expand Down
8 changes: 2 additions & 6 deletions src/org.cc
Expand Up @@ -63,14 +63,10 @@ NAN_METHOD(Org::lookupSync) {
NanScope();

Local<Value> data = NanNew(NanNull());
Local<String> host_str = args[0]->ToString();
size_t size = host_str->Length() + 1;
char host_cstr[size];
size_t bc;
NanCString(args[0], &bc, host_cstr, size);
Org *o = ObjectWrap::Unwrap<Org>(args.This());

uint32_t ipnum = _GeoIP_lookupaddress(host_cstr);
static NanUtf8String *host_cstr = new NanUtf8String(args[0]);
uint32_t ipnum = _GeoIP_lookupaddress(**host_cstr);

if (ipnum <= 0) {
NanReturnValue(NanNull());
Expand Down
8 changes: 2 additions & 6 deletions src/region.cc
Expand Up @@ -64,14 +64,10 @@ NAN_METHOD(Region::lookupSync) {
NanScope();

Local<Object> data = NanNew<Object>();
Local<String> host_str = args[0]->ToString();
size_t size = host_str->Length() + 1;
char host_cstr[size];
size_t bc;
NanCString(args[0], &bc, host_cstr, size);
Region *r = ObjectWrap::Unwrap<Region>(args.This());

uint32_t ipnum = _GeoIP_lookupaddress(host_cstr);
static NanUtf8String *host_cstr = new NanUtf8String(args[0]);
uint32_t ipnum = _GeoIP_lookupaddress(**host_cstr);

if (ipnum <= 0) {
NanReturnValue(NanNull());
Expand Down
2 changes: 1 addition & 1 deletion test/netspeedcell.mocha.js
Expand Up @@ -87,7 +87,7 @@ describe('NetSpeedCell', function() {
should.not.exist(err);
should.exist(data);
data.should.be.an('string');
data.should.equal("Dialup");
data.should.equal("Cable/DSL");
setTimeout(done, 1);
});
});
Expand Down

0 comments on commit 6feda69

Please sign in to comment.