ba46253
diff --git a/README.md b/README.md
ba46253
index 85a3d1f..806b3cd 100644
ba46253
--- a/README.md
ba46253
+++ b/README.md
ba46253
@@ -46,6 +46,12 @@ For more details, please visit:
ba46253
 * Use the IPv4 BIN file if you just need to query IPv4 addresses.
ba46253
 * Use the IPv6 BIN file if you need to query BOTH IPv4 and IPv6 addresses.
ba46253
 
ba46253
+# NOTES
ba46253
+If you encountered **error while loading shared libraries** in linux platform, that could be due to the shared library was saved into **usr/local/lib** that might not be the default library path. You can run the below command
ba46253
+```
ba46253
+ldconfig /usr/local/lib
ba46253
+```
ba46253
+
ba46253
 # Support
ba46253
 Email: support@ip2location.com.  
ba46253
 URL: [https://www.ip2location.com](https://www.ip2location.com)
ba46253
diff --git a/contrib/IP2Location.spec b/contrib/IP2Location.spec
ba46253
index 7b76cb8..8fed016 100644
ba46253
--- a/contrib/IP2Location.spec
ba46253
+++ b/contrib/IP2Location.spec
ba46253
@@ -3,12 +3,10 @@
ba46253
 Name:		IP2Location
ba46253
 Summary:	C library for mapping IP address to geolocation information
ba46253
 Version:	%{version}
ba46253
-Release:	5%{?dist}
ba46253
-Group:		System Environment/Libraries
ba46253
+Release:	6%{?dist}
ba46253
 License:	MIT
ba46253
 URL:		http://www.ip2location.com/
ba46253
-Source0:	https://github.com/chrislim2888/IP2Location-C-Library/archive/%{version}.tar.gz
ba46253
-BuildRoot:	%{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n)
ba46253
+Source0:	https://github.com/chrislim2888/IP2Location-C-Library/archive/%{version}/%{name}-%{version}.tar.gz
ba46253
 BuildRequires:	libtool
ba46253
 
ba46253
 
ba46253
@@ -26,7 +24,6 @@ the included downloader.
ba46253
 
ba46253
 %package 	devel
ba46253
 Summary:	Static library and header files for the ip2location library
ba46253
-Group:		Development/C
ba46253
 Requires:	%{name} = %{version}-%{release}
ba46253
 Provides:	%{name}-devel = %{version}-%{release}
ba46253
 
ba46253
@@ -51,63 +48,60 @@ perl -pi -e 's/-Wno-unused-result//' configure.ac
ba46253
 
ba46253
 %build
ba46253
 sh ./bootstrap
ba46253
-autoreconf -fi
ba46253
+autoreconf -fiv
ba46253
 
ba46253
 %configure --disable-static
ba46253
-make clean
ba46253
-make %{?_smp_mflags} COPTS="$RPM_OPT_FLAGS"
ba46253
+%make_build COPTS="$RPM_OPT_FLAGS"
ba46253
 
ba46253
 # convert CSV to BIN
ba46253
 make -C data convert
ba46253
 
ba46253
+
ba46253
 %check
ba46253
 LD_LIBRARY_PATH=%{buildroot}%{_libdir}:$LD_LIBRARY_PATH make check
ba46253
 
ba46253
 
ba46253
 %install
ba46253
-rm -rf %{buildroot}
ba46253
-
ba46253
-make install DESTDIR=%{buildroot}
ba46253
+%make_install
ba46253
 
ba46253
 # cleanup
ba46253
 rm -f %{buildroot}%{_libdir}/*.*a
ba46253
 
ba46253
 # tools
ba46253
 install -d %{buildroot}%{_datadir}/%{name}/tools
ba46253
-cp tools/download.pl %{buildroot}%{_datadir}/%{name}/tools
ba46253
+install -pm 0755 tools/download.pl %{buildroot}%{_datadir}/%{name}/tools
ba46253
 
ba46253
 # database directory
ba46253
 install -d %{buildroot}%{_datadir}/%{name}/
ba46253
 
ba46253
 
ba46253
-%post -p /sbin/ldconfig
ba46253
-
ba46253
-%postun -p /sbin/ldconfig
ba46253
-
ba46253
-
ba46253
-%clean
ba46253
-rm -rf %{buildroot}
ba46253
-
ba46253
 %files
ba46253
-%defattr(644,root,root,755)
ba46253
+%license COPYING LICENSE.TXT
ba46253
 
ba46253
-%doc AUTHORS ChangeLog COPYING README.md LICENSE.TXT NEWS INSTALL LICENSE.TXT
ba46253
+%doc AUTHORS ChangeLog README.md NEWS
ba46253
 
ba46253
-%attr(755,-,-) %{_libdir}/*.so*
ba46253
+%{_libdir}/libIP2Location.so.1
ba46253
+%{_libdir}/libIP2Location.so.1.0.0
ba46253
 
ba46253
-%attr(755,-,-) %{_datadir}/%{name}/tools/*
ba46253
+%{_datadir}/%{name}/tools/
ba46253
 
ba46253
 %dir %{_datadir}/%{name}/
ba46253
 
ba46253
 
ba46253
 %files devel
ba46253
-%defattr(-,root,root)
ba46253
-%{_includedir}/*
ba46253
+%{_includedir}/IP2Loc*.h
ba46253
+%{_libdir}/libIP2Location.so
ba46253
 
ba46253
 %doc Developers_Guide.txt
ba46253
 
ba46253
 
ba46253
 %changelog
ba46253
+* Fri Aug 28 2020 Peter Bieringer <pb@bieringer.de>
ba46253
+- fix spec file according to BZ#1873302
ba46253
+
ba46253
+* Sat Oct  5 2019 Peter Bieringer <pb@bieringer.de> - 8.0.9-5
ba46253
+- update version to 8.0.9
ba46253
+
ba46253
 * Sun Feb 26 2017 Peter Bieringer <pb@bieringer.de> - 8.0.4-5
ba46253
 - update to 8.0.4
ba46253
 - add some fixes related to move to github
ba46253
diff --git a/contrib/IP2Location.spec.in b/contrib/IP2Location.spec.in
ba46253
index b544e8a..be95898 100644
ba46253
--- a/contrib/IP2Location.spec.in
ba46253
+++ b/contrib/IP2Location.spec.in
ba46253
@@ -3,12 +3,10 @@
ba46253
 Name:		IP2Location
ba46253
 Summary:	C library for mapping IP address to geolocation information
ba46253
 Version:	%{version}
ba46253
-Release:	5%{?dist}
ba46253
-Group:		System Environment/Libraries
ba46253
+Release:	6%{?dist}
ba46253
 License:	MIT
ba46253
 URL:		http://www.ip2location.com/
ba46253
-Source0:	https://github.com/chrislim2888/IP2Location-C-Library/archive/%{version}.tar.gz
ba46253
-BuildRoot:	%{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n)
ba46253
+Source0:	https://github.com/chrislim2888/IP2Location-C-Library/archive/%{version}/%{name}-%{version}.tar.gz
ba46253
 BuildRequires:	libtool
ba46253
 
ba46253
 
ba46253
@@ -26,7 +24,6 @@ the included downloader.
ba46253
 
ba46253
 %package 	devel
ba46253
 Summary:	Static library and header files for the ip2location library
ba46253
-Group:		Development/C
ba46253
 Requires:	%{name} = %{version}-%{release}
ba46253
 Provides:	%{name}-devel = %{version}-%{release}
ba46253
 
ba46253
@@ -51,63 +48,60 @@ perl -pi -e 's/-Wno-unused-result//' configure.ac
ba46253
 
ba46253
 %build
ba46253
 sh ./bootstrap
ba46253
-autoreconf -fi
ba46253
+autoreconf -fiv
ba46253
 
ba46253
 %configure --disable-static
ba46253
-make clean
ba46253
-make %{?_smp_mflags} COPTS="$RPM_OPT_FLAGS"
ba46253
+%make_build COPTS="$RPM_OPT_FLAGS"
ba46253
 
ba46253
 # convert CSV to BIN
ba46253
 make -C data convert
ba46253
 
ba46253
+
ba46253
 %check
ba46253
 LD_LIBRARY_PATH=%{buildroot}%{_libdir}:$LD_LIBRARY_PATH make check
ba46253
 
ba46253
 
ba46253
 %install
ba46253
-rm -rf %{buildroot}
ba46253
-
ba46253
-make install DESTDIR=%{buildroot}
ba46253
+%make_install
ba46253
 
ba46253
 # cleanup
ba46253
 rm -f %{buildroot}%{_libdir}/*.*a
ba46253
 
ba46253
 # tools
ba46253
 install -d %{buildroot}%{_datadir}/%{name}/tools
ba46253
-cp tools/download.pl %{buildroot}%{_datadir}/%{name}/tools
ba46253
+install -pm 0755 tools/download.pl %{buildroot}%{_datadir}/%{name}/tools
ba46253
 
ba46253
 # database directory
ba46253
 install -d %{buildroot}%{_datadir}/%{name}/
ba46253
 
ba46253
 
ba46253
-%post -p /sbin/ldconfig
ba46253
-
ba46253
-%postun -p /sbin/ldconfig
ba46253
-
ba46253
-
ba46253
-%clean
ba46253
-rm -rf %{buildroot}
ba46253
-
ba46253
 %files
ba46253
-%defattr(644,root,root,755)
ba46253
+%license COPYING LICENSE.TXT
ba46253
 
ba46253
-%doc AUTHORS ChangeLog COPYING README.md LICENSE.TXT NEWS INSTALL LICENSE.TXT
ba46253
+%doc AUTHORS ChangeLog README.md NEWS
ba46253
 
ba46253
-%attr(755,-,-) %{_libdir}/*.so*
ba46253
+%{_libdir}/libIP2Location.so.1
ba46253
+%{_libdir}/libIP2Location.so.1.0.0
ba46253
 
ba46253
-%attr(755,-,-) %{_datadir}/%{name}/tools/*
ba46253
+%{_datadir}/%{name}/tools/
ba46253
 
ba46253
 %dir %{_datadir}/%{name}/
ba46253
 
ba46253
 
ba46253
 %files devel
ba46253
-%defattr(-,root,root)
ba46253
-%{_includedir}/*
ba46253
+%{_includedir}/IP2Loc*.h
ba46253
+%{_libdir}/libIP2Location.so
ba46253
 
ba46253
 %doc Developers_Guide.txt
ba46253
 
ba46253
 
ba46253
 %changelog
ba46253
+* Fri Aug 28 2020 Peter Bieringer <pb@bieringer.de>
ba46253
+- fix spec file according to BZ#1873302
ba46253
+
ba46253
+* Sat Oct  5 2019 Peter Bieringer <pb@bieringer.de> - 8.0.9-5
ba46253
+- update version to 8.0.9
ba46253
+
ba46253
 * Sun Feb 26 2017 Peter Bieringer <pb@bieringer.de> - 8.0.4-5
ba46253
 - update to 8.0.4
ba46253
 - add some fixes related to move to github
ba46253
diff --git a/libIP2Location/IP2Loc_DBInterface.c b/libIP2Location/IP2Loc_DBInterface.c
ba46253
index 647ea69..2130e99 100644
ba46253
--- a/libIP2Location/IP2Loc_DBInterface.c
ba46253
+++ b/libIP2Location/IP2Loc_DBInterface.c
ba46253
@@ -271,9 +271,13 @@ uint32_t IP2Location_read32(FILE *handle, uint32_t position)
ba46253
     {
ba46253
         fseek(handle, position-1, 0);
ba46253
         temp = fread(&byte1, 1, 1, handle);
ba46253
+	if (temp == 0) { return 0; };
ba46253
         temp = fread(&byte2, 1, 1, handle);
ba46253
+	if (temp == 0) { return 0; };
ba46253
         temp = fread(&byte3, 1, 1, handle);
ba46253
+	if (temp == 0) { return 0; };
ba46253
         temp = fread(&byte4, 1, 1, handle);
ba46253
+	if (temp == 0) { return 0; };
ba46253
     }
ba46253
     else
ba46253
     {
ba46253
@@ -295,6 +299,7 @@ uint8_t IP2Location_read8(FILE *handle, uint32_t position)
ba46253
     {
ba46253
         fseek(handle, position-1, 0);
ba46253
         temp = fread(&ret, 1, 1, handle);
ba46253
+	if (temp == 0) { return 0; };
ba46253
     }
ba46253
     else
ba46253
     {
ba46253
@@ -309,13 +314,16 @@ char *IP2Location_readStr(FILE *handle, uint32_t position)
ba46253
     char *str = 0;
ba46253
     uint8_t *cache_shm = cache_shm_ptr;
ba46253
     size_t temp;
ba46253
+
ba46253
     if (DB_access_type == IP2LOCATION_FILE_IO && handle != NULL)
ba46253
     {
ba46253
         fseek(handle, position, 0);
ba46253
         temp = fread(&size, 1, 1, handle);
ba46253
+	if (temp == 0) { return ""; };
ba46253
         str = (char *)malloc(size+1);
ba46253
         memset(str, 0, size+1);
ba46253
         temp = fread(str, size, 1, handle);
ba46253
+	if (temp == 0) { return ""; };
ba46253
     }
ba46253
     else
ba46253
     {
ba46253
@@ -341,9 +349,13 @@ float IP2Location_readFloat(FILE *handle, uint32_t position)
ba46253
     {
ba46253
         fseek(handle, position-1, 0);
ba46253
         temp = fread(p+3, 1, 1, handle);
ba46253
+	if (temp == 0) { return 0.0; };
ba46253
         temp = fread(p+2, 1, 1, handle);
ba46253
+	if (temp == 0) { return 0.0; };
ba46253
         temp = fread(p+1, 1, 1, handle);
ba46253
+	if (temp == 0) { return 0.0; };
ba46253
         temp = fread(p,   1, 1, handle);
ba46253
+	if (temp == 0) { return 0.0; };
ba46253
     }
ba46253
     else
ba46253
     {
ba46253
@@ -357,6 +369,7 @@ float IP2Location_readFloat(FILE *handle, uint32_t position)
ba46253
     {
ba46253
         fseek(handle, position-1, 0);
ba46253
         temp = fread(&ret, 4, 1, handle);
ba46253
+	if (temp == 0) { return 0.0; };
ba46253
     }
ba46253
     else
ba46253
     {
ba46253
@@ -365,5 +378,3 @@ float IP2Location_readFloat(FILE *handle, uint32_t position)
ba46253
 #endif
ba46253
     return ret;
ba46253
 }
ba46253
-
ba46253
-
ba46253
diff --git a/libIP2Location/IP2Location.c b/libIP2Location/IP2Location.c
ba46253
index fbe7fe0..a036580 100644
ba46253
--- a/libIP2Location/IP2Location.c
ba46253
+++ b/libIP2Location/IP2Location.c
ba46253
@@ -61,7 +61,6 @@ uint8_t USAGETYPE_POSITION[25]           = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
ba46253
 static int IP2Location_initialize(IP2Location *loc);
ba46253
 static IP2LocationRecord *IP2Location_new_record();
ba46253
 static uint32_t IP2Location_ip2no(char* ip);
ba46253
-static struct in6_addr_local  IP2Location_ipv6_to_no(char* ipaddr);
ba46253
 static int IP2Location_ip_is_ipv4 (char* ipaddr);
ba46253
 static int IP2Location_ip_is_ipv6 (char* ipaddr);
ba46253
 static IP2LocationRecord *IP2Location_get_record(IP2Location *loc, char *ip, uint32_t mode);
ba46253
@@ -151,8 +150,8 @@ static int IP2Location_initialize(IP2Location *loc)
ba46253
     loc->ipv6databasecount  = IP2Location_read32(loc->filehandle, 14);
ba46253
     loc->ipv6databaseaddr   = IP2Location_read32(loc->filehandle, 18);
ba46253
 
ba46253
-    loc->ipv4indexbaseaddr 	= IP2Location_read32(loc->filehandle, 22);
ba46253
-    loc->ipv6indexbaseaddr	= IP2Location_read32(loc->filehandle, 26);
ba46253
+    loc->ipv4indexbaseaddr     = IP2Location_read32(loc->filehandle, 22);
ba46253
+    loc->ipv6indexbaseaddr    = IP2Location_read32(loc->filehandle, 26);
ba46253
 
ba46253
     return 0;
ba46253
 }
ba46253
@@ -381,47 +380,77 @@ static IP2LocationRecord *IP2Location_read_record(IP2Location *loc, uint32_t row
ba46253
 
ba46253
     if ((mode & COUNTRYSHORT) && (COUNTRY_POSITION[dbtype] != 0))
ba46253
     {
ba46253
-        record->country_short = IP2Location_readStr(handle, IP2Location_read32(handle, rowaddr + 4 * (COUNTRY_POSITION[dbtype]-1)));
ba46253
+        if (!record->country_short)
ba46253
+        {
ba46253
+            record->country_short = IP2Location_readStr(handle, IP2Location_read32(handle, rowaddr + 4 * (COUNTRY_POSITION[dbtype]-1)));
ba46253
+        }
ba46253
     }
ba46253
     else
ba46253
     {
ba46253
-        record->country_short = strdup(NOT_SUPPORTED);
ba46253
+        if (!record->country_short)
ba46253
+        {
ba46253
+            record->country_short = strdup(NOT_SUPPORTED);
ba46253
+        }
ba46253
     }
ba46253
 
ba46253
     if ((mode & COUNTRYLONG) && (COUNTRY_POSITION[dbtype] != 0))
ba46253
     {
ba46253
-        record->country_long = IP2Location_readStr(handle, IP2Location_read32(handle, rowaddr + 4 * (COUNTRY_POSITION[dbtype]-1))+3);
ba46253
+        if (!record->country_long)
ba46253
+        {
ba46253
+            record->country_long = IP2Location_readStr(handle, IP2Location_read32(handle, rowaddr + 4 * (COUNTRY_POSITION[dbtype]-1))+3);
ba46253
+        }
ba46253
     }
ba46253
     else
ba46253
     {
ba46253
-        record->country_long = strdup(NOT_SUPPORTED);
ba46253
+        if (!record->country_long)
ba46253
+        {
ba46253
+            record->country_long = strdup(NOT_SUPPORTED);
ba46253
+        }
ba46253
     }
ba46253
 
ba46253
     if ((mode & REGION) && (REGION_POSITION[dbtype] != 0))
ba46253
     {
ba46253
-        record->region = IP2Location_readStr(handle, IP2Location_read32(handle, rowaddr + 4 * (REGION_POSITION[dbtype]-1)));
ba46253
+        if (!record->region)
ba46253
+        {
ba46253
+            record->region = IP2Location_readStr(handle, IP2Location_read32(handle, rowaddr + 4 * (REGION_POSITION[dbtype]-1)));
ba46253
+        }
ba46253
     }
ba46253
     else
ba46253
     {
ba46253
-        record->region = strdup(NOT_SUPPORTED);
ba46253
+        if (!record->region)
ba46253
+        {
ba46253
+            record->region = strdup(NOT_SUPPORTED);
ba46253
+        }
ba46253
     }
ba46253
 
ba46253
     if ((mode & CITY) && (CITY_POSITION[dbtype] != 0))
ba46253
     {
ba46253
-        record->city = IP2Location_readStr(handle, IP2Location_read32(handle, rowaddr + 4 * (CITY_POSITION[dbtype]-1)));
ba46253
+        if (!record->city)
ba46253
+        {
ba46253
+            record->city = IP2Location_readStr(handle, IP2Location_read32(handle, rowaddr + 4 * (CITY_POSITION[dbtype]-1)));
ba46253
+        }
ba46253
     }
ba46253
     else
ba46253
     {
ba46253
-        record->city = strdup(NOT_SUPPORTED);
ba46253
+        if (!record->city)
ba46253
+        {
ba46253
+            record->city = strdup(NOT_SUPPORTED);
ba46253
+        }
ba46253
     }
ba46253
 
ba46253
     if ((mode & ISP) && (ISP_POSITION[dbtype] != 0))
ba46253
     {
ba46253
-        record->isp = IP2Location_readStr(handle, IP2Location_read32(handle, rowaddr + 4 * (ISP_POSITION[dbtype]-1)));
ba46253
+        if (!record->isp)
ba46253
+        {
ba46253
+            record->isp = IP2Location_readStr(handle, IP2Location_read32(handle, rowaddr + 4 * (ISP_POSITION[dbtype]-1)));
ba46253
+        }
ba46253
     }
ba46253
     else
ba46253
     {
ba46253
-        record->isp = strdup(NOT_SUPPORTED);
ba46253
+        if (!record->isp)
ba46253
+        {
ba46253
+            record->isp = strdup(NOT_SUPPORTED);
ba46253
+        }
ba46253
     }
ba46253
 
ba46253
     if ((mode & LATITUDE) && (LATITUDE_POSITION[dbtype] != 0))
ba46253
@@ -444,108 +473,174 @@ static IP2LocationRecord *IP2Location_read_record(IP2Location *loc, uint32_t row
ba46253
 
ba46253
     if ((mode & DOMAIN_) && (DOMAIN_POSITION[dbtype] != 0))
ba46253
     {
ba46253
-        record->domain = IP2Location_readStr(handle, IP2Location_read32(handle, rowaddr + 4 * (DOMAIN_POSITION[dbtype]-1)));
ba46253
+        if (!record->domain)
ba46253
+        {
ba46253
+            record->domain = IP2Location_readStr(handle, IP2Location_read32(handle, rowaddr + 4 * (DOMAIN_POSITION[dbtype]-1)));
ba46253
+        }
ba46253
     }
ba46253
     else
ba46253
     {
ba46253
-        record->domain = strdup(NOT_SUPPORTED);
ba46253
+        if (!record->domain)
ba46253
+        {
ba46253
+            record->domain = strdup(NOT_SUPPORTED);
ba46253
+        }
ba46253
     }
ba46253
 
ba46253
     if ((mode & ZIPCODE) && (ZIPCODE_POSITION[dbtype] != 0))
ba46253
     {
ba46253
-        record->zipcode = IP2Location_readStr(handle, IP2Location_read32(handle, rowaddr + 4 * (ZIPCODE_POSITION[dbtype]-1)));
ba46253
+        if (!record->zipcode)
ba46253
+        {
ba46253
+            record->zipcode = IP2Location_readStr(handle, IP2Location_read32(handle, rowaddr + 4 * (ZIPCODE_POSITION[dbtype]-1)));
ba46253
+        }
ba46253
     }
ba46253
     else
ba46253
     {
ba46253
-        record->zipcode = strdup(NOT_SUPPORTED);
ba46253
+        if (!record->zipcode)
ba46253
+        {
ba46253
+            record->zipcode = strdup(NOT_SUPPORTED);
ba46253
+        }
ba46253
     }
ba46253
 
ba46253
     if ((mode & TIMEZONE) && (TIMEZONE_POSITION[dbtype] != 0))
ba46253
     {
ba46253
-        record->timezone = IP2Location_readStr(handle, IP2Location_read32(handle, rowaddr + 4 * (TIMEZONE_POSITION[dbtype]-1)));
ba46253
+        if (!record->timezone)
ba46253
+        {
ba46253
+            record->timezone = IP2Location_readStr(handle, IP2Location_read32(handle, rowaddr + 4 * (TIMEZONE_POSITION[dbtype]-1)));
ba46253
+        }
ba46253
     }
ba46253
     else
ba46253
     {
ba46253
-        record->timezone = strdup(NOT_SUPPORTED);
ba46253
+        if (!record->timezone)
ba46253
+        {
ba46253
+            record->timezone = strdup(NOT_SUPPORTED);
ba46253
+        }
ba46253
     }
ba46253
 
ba46253
     if ((mode & NETSPEED) && (NETSPEED_POSITION[dbtype] != 0))
ba46253
     {
ba46253
-        record->netspeed = IP2Location_readStr(handle, IP2Location_read32(handle, rowaddr + 4 * (NETSPEED_POSITION[dbtype]-1)));
ba46253
+        if (!record->netspeed)
ba46253
+        {
ba46253
+            record->netspeed = IP2Location_readStr(handle, IP2Location_read32(handle, rowaddr + 4 * (NETSPEED_POSITION[dbtype]-1)));
ba46253
+        }
ba46253
     }
ba46253
     else
ba46253
     {
ba46253
-        record->netspeed = strdup(NOT_SUPPORTED);
ba46253
+        if (!record->netspeed)
ba46253
+        {
ba46253
+            record->netspeed = strdup(NOT_SUPPORTED);
ba46253
+        }
ba46253
     }
ba46253
 
ba46253
     if ((mode & IDDCODE) && (IDDCODE_POSITION[dbtype] != 0))
ba46253
     {
ba46253
-        record->iddcode = IP2Location_readStr(handle, IP2Location_read32(handle, rowaddr + 4 * (IDDCODE_POSITION[dbtype]-1)));
ba46253
+        if (!record->iddcode)
ba46253
+        {
ba46253
+            record->iddcode = IP2Location_readStr(handle, IP2Location_read32(handle, rowaddr + 4 * (IDDCODE_POSITION[dbtype]-1)));
ba46253
+        }
ba46253
     }
ba46253
     else
ba46253
     {
ba46253
-        record->iddcode = strdup(NOT_SUPPORTED);
ba46253
+        if (!record->iddcode)
ba46253
+        {
ba46253
+            record->iddcode = strdup(NOT_SUPPORTED);
ba46253
+        }
ba46253
     }
ba46253
 
ba46253
     if ((mode & AREACODE) && (AREACODE_POSITION[dbtype] != 0))
ba46253
     {
ba46253
-        record->areacode = IP2Location_readStr(handle, IP2Location_read32(handle, rowaddr + 4 * (AREACODE_POSITION[dbtype]-1)));
ba46253
+        if (!record->areacode)
ba46253
+        {
ba46253
+            record->areacode = IP2Location_readStr(handle, IP2Location_read32(handle, rowaddr + 4 * (AREACODE_POSITION[dbtype]-1)));
ba46253
+        }
ba46253
     }
ba46253
     else
ba46253
     {
ba46253
-        record->areacode = strdup(NOT_SUPPORTED);
ba46253
+        if (!record->areacode)
ba46253
+        {
ba46253
+            record->areacode = strdup(NOT_SUPPORTED);
ba46253
+        }
ba46253
     }
ba46253
 
ba46253
     if ((mode & WEATHERSTATIONCODE) && (WEATHERSTATIONCODE_POSITION[dbtype] != 0))
ba46253
     {
ba46253
-        record->weatherstationcode = IP2Location_readStr(handle, IP2Location_read32(handle, rowaddr + 4 * (WEATHERSTATIONCODE_POSITION[dbtype]-1)));
ba46253
+        if (!record->weatherstationcode)
ba46253
+        {
ba46253
+            record->weatherstationcode = IP2Location_readStr(handle, IP2Location_read32(handle, rowaddr + 4 * (WEATHERSTATIONCODE_POSITION[dbtype]-1)));
ba46253
+        }
ba46253
     }
ba46253
     else
ba46253
     {
ba46253
-        record->weatherstationcode = strdup(NOT_SUPPORTED);
ba46253
+        if (!record->weatherstationcode)
ba46253
+        {
ba46253
+            record->weatherstationcode = strdup(NOT_SUPPORTED);
ba46253
+        }
ba46253
     }
ba46253
 
ba46253
     if ((mode & WEATHERSTATIONNAME) && (WEATHERSTATIONNAME_POSITION[dbtype] != 0))
ba46253
     {
ba46253
-        record->weatherstationname = IP2Location_readStr(handle, IP2Location_read32(handle, rowaddr + 4 * (WEATHERSTATIONNAME_POSITION[dbtype]-1)));
ba46253
+        if (!record->weatherstationname)
ba46253
+        {
ba46253
+            record->weatherstationname = IP2Location_readStr(handle, IP2Location_read32(handle, rowaddr + 4 * (WEATHERSTATIONNAME_POSITION[dbtype]-1)));
ba46253
+        }
ba46253
     }
ba46253
     else
ba46253
     {
ba46253
-        record->weatherstationname = strdup(NOT_SUPPORTED);
ba46253
+        if (!record->weatherstationname)
ba46253
+        {
ba46253
+            record->weatherstationname = strdup(NOT_SUPPORTED);
ba46253
+        }
ba46253
     }
ba46253
 
ba46253
     if ((mode & MCC) && (MCC_POSITION[dbtype] != 0))
ba46253
     {
ba46253
-        record->mcc = IP2Location_readStr(handle, IP2Location_read32(handle, rowaddr + 4 * (MCC_POSITION[dbtype]-1)));
ba46253
+        if (!record->mcc)
ba46253
+        {
ba46253
+            record->mcc = IP2Location_readStr(handle, IP2Location_read32(handle, rowaddr + 4 * (MCC_POSITION[dbtype]-1)));
ba46253
+        }
ba46253
     }
ba46253
     else
ba46253
     {
ba46253
-        record->mcc = strdup(NOT_SUPPORTED);
ba46253
+        if (!record->mcc)
ba46253
+        {
ba46253
+            record->mcc = strdup(NOT_SUPPORTED);
ba46253
+        }
ba46253
     }
ba46253
 
ba46253
     if ((mode & MNC) && (MNC_POSITION[dbtype] != 0))
ba46253
     {
ba46253
-        record->mnc = IP2Location_readStr(handle, IP2Location_read32(handle, rowaddr + 4 * (MNC_POSITION[dbtype]-1)));
ba46253
+        if (!record->mnc)
ba46253
+        {
ba46253
+            record->mnc = IP2Location_readStr(handle, IP2Location_read32(handle, rowaddr + 4 * (MNC_POSITION[dbtype]-1)));
ba46253
+        }
ba46253
     }
ba46253
     else
ba46253
     {
ba46253
-        record->mnc = strdup(NOT_SUPPORTED);
ba46253
+        if (!record->mnc)
ba46253
+        {
ba46253
+            record->mnc = strdup(NOT_SUPPORTED);
ba46253
+        }
ba46253
     }
ba46253
 
ba46253
     if ((mode & MOBILEBRAND) && (MOBILEBRAND_POSITION[dbtype] != 0))
ba46253
     {
ba46253
-        record->mobilebrand = IP2Location_readStr(handle, IP2Location_read32(handle, rowaddr + 4 * (MOBILEBRAND_POSITION[dbtype]-1)));
ba46253
+        if (!record->mobilebrand)
ba46253
+        {
ba46253
+            record->mobilebrand = IP2Location_readStr(handle, IP2Location_read32(handle, rowaddr + 4 * (MOBILEBRAND_POSITION[dbtype]-1)));
ba46253
+        }
ba46253
     }
ba46253
     else
ba46253
     {
ba46253
-        record->mobilebrand = strdup(NOT_SUPPORTED);
ba46253
+        if (!record->mobilebrand)
ba46253
+        {
ba46253
+            record->mobilebrand = strdup(NOT_SUPPORTED);
ba46253
+        }
ba46253
     }
ba46253
 
ba46253
     if ((mode & ELEVATION) && (ELEVATION_POSITION[dbtype] != 0))
ba46253
     {
ba46253
         char *mem = IP2Location_readStr(handle, IP2Location_read32(handle, rowaddr + 4 * (ELEVATION_POSITION[dbtype]-1)));
ba46253
-	record->elevation = atof(mem);
ba46253
-	free(mem);
ba46253
+        record->elevation = atof(mem);
ba46253
+        free(mem);
ba46253
     }
ba46253
     else
ba46253
     {
ba46253
@@ -554,11 +649,17 @@ static IP2LocationRecord *IP2Location_read_record(IP2Location *loc, uint32_t row
ba46253
 
ba46253
     if ((mode & USAGETYPE) && (USAGETYPE_POSITION[dbtype] != 0))
ba46253
     {
ba46253
-        record->usagetype = IP2Location_readStr(handle, IP2Location_read32(handle, rowaddr + 4 * (USAGETYPE_POSITION[dbtype]-1)));
ba46253
+        if (!record->usagetype)
ba46253
+        {
ba46253
+            record->usagetype = IP2Location_readStr(handle, IP2Location_read32(handle, rowaddr + 4 * (USAGETYPE_POSITION[dbtype]-1)));
ba46253
+        }
ba46253
     }
ba46253
     else
ba46253
     {
ba46253
-        record->usagetype = strdup(NOT_SUPPORTED);
ba46253
+        if (!record->usagetype)
ba46253
+        {
ba46253
+            record->usagetype = strdup(NOT_SUPPORTED);
ba46253
+        }
ba46253
     }
ba46253
     return record;
ba46253
 }
ba46253
@@ -658,7 +759,7 @@ static IP2LocationRecord *IP2Location_get_ipv4_record(IP2Location *loc, char *ip
ba46253
     {
ba46253
         mid = (uint32_t)((low + high) >> 1);
ba46253
         ipfrom = IP2Location_read32(handle, baseaddr + mid * dbcolumn * 4);
ba46253
-        ipto 	= IP2Location_read32(handle, baseaddr + (mid + 1) * dbcolumn * 4);
ba46253
+        ipto     = IP2Location_read32(handle, baseaddr + (mid + 1) * dbcolumn * 4);
ba46253
 
ba46253
         if ((ipno >= ipfrom) && (ipno < ipto))
ba46253
         {
ba46253
@@ -683,17 +784,17 @@ static IP2LocationRecord *IP2Location_get_ipv4_record(IP2Location *loc, char *ip
ba46253
 static IP2LocationRecord *IP2Location_get_record(IP2Location *loc, char *ipstring, uint32_t mode)
ba46253
 {
ba46253
     ipv_t parsed_ipv = IP2Location_parse_addr(ipstring);
ba46253
-	if (parsed_ipv.ipversion == 4)
ba46253
-	{
ba46253
-		//process IPv4
ba46253
-		return IP2Location_get_ipv4_record(loc, ipstring, mode, parsed_ipv);
ba46253
-	}
ba46253
+    if (parsed_ipv.ipversion == 4)
ba46253
+    {
ba46253
+        //process IPv4
ba46253
+        return IP2Location_get_ipv4_record(loc, ipstring, mode, parsed_ipv);
ba46253
+    }
ba46253
     if (parsed_ipv.ipversion == 6)
ba46253
     {
ba46253
-		//process IPv6
ba46253
+        //process IPv6
ba46253
         return IP2Location_get_ipv6_record(loc, ipstring, mode, parsed_ipv);
ba46253
     }
ba46253
-	else
ba46253
+    else
ba46253
     {
ba46253
         return IP2Location_bad_record(INVALID_IPV4_ADDRESS);
ba46253
     }
ba46253
diff --git a/libIP2Location/IP2Location.h b/libIP2Location/IP2Location.h
ba46253
index b425362..34e9ada 100644
ba46253
--- a/libIP2Location/IP2Location.h
ba46253
+++ b/libIP2Location/IP2Location.h
ba46253
@@ -56,7 +56,7 @@ extern "C" {
ba46253
 #include "IP2Loc_DBInterface.h"
ba46253
 
ba46253
 /* API version changes only if functions are added (release) or changed (minor/major) */
ba46253
-#define API_VERSION   8.0.8
ba46253
+#define API_VERSION   8.0.9
ba46253
 
ba46253
 
ba46253
 #define API_VERSION_MAJOR   8
ba46253
diff --git a/test/test-IP2Location.c b/test/test-IP2Location.c
ba46253
index f48eb3f..9ad08a2 100644
ba46253
--- a/test/test-IP2Location.c
ba46253
+++ b/test/test-IP2Location.c
ba46253
@@ -38,7 +38,10 @@ int main () {
ba46253
 	f = fopen("country_test_ipv4_data.txt","r");
ba46253
 
ba46253
 	while (fscanf(f, "%s", ipAddress) != EOF) {
ba46253
-		fscanf(f, "%s", expectedCountry);
ba46253
+		if (fscanf(f, "%s", expectedCountry) == EOF) {
ba46253
+			printf("Unexpected EOF, input file broken: country_test_ipv6_data.txt\n");
ba46253
+			return -1;
ba46253
+		};
ba46253
 		record = IP2Location_get_all(IP2LocationObj, ipAddress);
ba46253
 		if (record != NULL)	{
ba46253
 			if (strcmp(expectedCountry,record->country_short) != 0) {
ba46253
@@ -86,7 +89,10 @@ int main () {
ba46253
 	f = fopen("country_test_ipv6_data.txt","r");
ba46253
 	
ba46253
 	while (fscanf(f, "%s", ipAddress) != EOF) {
ba46253
-		fscanf(f, "%s", expectedCountry);
ba46253
+		if (fscanf(f, "%s", expectedCountry) == EOF) {
ba46253
+			printf("Unexpected EOF, input file broken: country_test_ipv6_data.txt\n");
ba46253
+			return -1;
ba46253
+		};
ba46253
 		record = IP2Location_get_all(IP2LocationObj, ipAddress);
ba46253
 		if (strcmp(expectedCountry,record->country_short) != 0) {
ba46253
 			fprintf(stdout,"Test IP Address %s (Test %d) failed. We got %s but expected %s,\n",ipAddress,test_num,record->country_short,expectedCountry);