From 56c83f38951fad087b0ec5055f03a3df114aa26a Mon Sep 17 00:00:00 2001 From: chenxin Date: Thu, 5 Nov 2015 12:48:24 +0800 Subject: [PATCH] optimized the header block size & fix the may comming leak for c binding --- binding/c/ip2region.c | 2 ++ binding/c/ip2region.h | 2 +- .../java/src/org/lionsoul/ip2region/DbSearcher.java | 13 ++++++++++++- binding/php/Ip2Region.class.php | 2 +- 4 files changed, 16 insertions(+), 3 deletions(-) diff --git a/binding/c/ip2region.c b/binding/c/ip2region.c index 398350f..73bc909 100644 --- a/binding/c/ip2region.c +++ b/binding/c/ip2region.c @@ -36,6 +36,8 @@ IP2R_API uint_t ip2region_create(ip2region_t ip2rObj, char *dbFile) ip2rObj->dbHandler = fopen(dbFile, "rb"); if ( ip2rObj->dbHandler == NULL ) { + IP2R_FREE(ip2rObj->HeaderSip); + IP2R_FREE(ip2rObj->HeaderPtr); return 0; } diff --git a/binding/c/ip2region.h b/binding/c/ip2region.h index d288638..2b560f6 100644 --- a/binding/c/ip2region.h +++ b/binding/c/ip2region.h @@ -44,7 +44,7 @@ typedef unsigned int uint_t; typedef unsigned long ulong_t; #define INDEX_BLOCK_LENGTH 12 -#define TOTAL_HEADER_LENGTH 8192 +#define TOTAL_HEADER_LENGTH 4096 /* * ip2region properties struct diff --git a/binding/java/src/org/lionsoul/ip2region/DbSearcher.java b/binding/java/src/org/lionsoul/ip2region/DbSearcher.java index c5db666..01f69cb 100644 --- a/binding/java/src/org/lionsoul/ip2region/DbSearcher.java +++ b/binding/java/src/org/lionsoul/ip2region/DbSearcher.java @@ -91,7 +91,8 @@ public class DbSearcher if ( HeaderSip == null ) { raf.seek(8L); //pass the super block - byte[] b = new byte[dbConfig.getTotalHeaderSize()]; + //byte[] b = new byte[dbConfig.getTotalHeaderSize()]; + byte[] b = new byte[4096]; raf.readFully(b, 0, b.length); //fill the header @@ -290,6 +291,16 @@ public class DbSearcher { return binarySearch(Util.ip2long(ip)); } + + /** + * get the db config + * + * @return DbConfig + */ + public DbConfig getDbConfig() + { + return dbConfig; + } /** * close the db diff --git a/binding/php/Ip2Region.class.php b/binding/php/Ip2Region.class.php index 03c8e3f..8bfe64e 100644 --- a/binding/php/Ip2Region.class.php +++ b/binding/php/Ip2Region.class.php @@ -7,7 +7,7 @@ */ defined('INDEX_BLOCK_LENGTH') or define('INDEX_BLOCK_LENGTH', 12); -defined('TOTAL_HEADER_LENGTH') or define('TOTAL_HEADER_LENGTH', 8192); +defined('TOTAL_HEADER_LENGTH') or define('TOTAL_HEADER_LENGTH', 4096); class Ip2Region {