Skip to content

Commit 5b894f5

Browse files
Merge pull request #2 from UADuke/patch-1
Fixed "error:emfile" after many queries.
2 parents fa4167c + 991bccb commit 5b894f5

1 file changed

Lines changed: 4 additions & 2 deletions

File tree

ip2location.erl

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,7 @@ query(Ip) ->
327327
[{_, Ipv4columnsize}] = ets:lookup(mymeta, ipv4columnsize),
328328
[{_, Ipv6columnsize}] = ets:lookup(mymeta, ipv6columnsize),
329329

330-
case inet:parse_address(Ip) of
330+
Result = case inet:parse_address(Ip) of
331331
{ok, {X1, X2, X3, X4}} ->
332332
Ipnum = (X1 bsl 24) + (X2 bsl 16) + (X3 bsl 8) + (X4),
333333
search4(S, Ipnum, Databasetype, 0, Ipv4databasecount, Ipv4databaseaddr, Ipv4indexbaseaddr, Ipv4columnsize);
@@ -346,7 +346,9 @@ query(Ip) ->
346346
{_, _} ->
347347
io:format("Error: Invalid IP address.~n", []),
348348
{} % return empty
349-
end
349+
end,
350+
file:close(S),
351+
Result
350352
end
351353
end.
352354

0 commit comments

Comments
 (0)