telize

High performance JSON IP and GeoIP REST API (IP Geolocation)
Log | Files | Refs | README | LICENSE

commit a7cd71672b102068123eedf549b346c814dec351
parent 71a43b4e44c9eb1335f8adaed056ac6f1c212dd4
Author: Frederic Cambus <fred@statdns.com>
Date:   Fri,  5 Oct 2018 13:38:34 +0200

Use kore_malloc to allocate memory for addr, so we can free this memory

Diffstat:
Msrc/ip.c | 8++++++--
Msrc/jsonip.c | 8++++++--
Msrc/location.c | 6+++++-
3 files changed, 17 insertions(+), 5 deletions(-)

diff --git a/src/ip.c b/src/ip.c @@ -5,7 +5,7 @@ /* https://www.telize.com */ /* */ /* Created: 2013-08-15 */ -/* Last Updated: 2018-10-04 */ +/* Last Updated: 2018-10-05 */ /* */ /* Telize is released under the BSD 2-Clause license. */ /* See LICENSE file for details. */ @@ -23,7 +23,9 @@ int ip(struct http_request *req) { const char *visitor_ip; - char *ip, addr[INET6_ADDRSTRLEN]; + char *ip, *addr; + + addr = kore_malloc(INET6_ADDRSTRLEN); if (req->owner->addrtype == AF_INET) { inet_ntop(req->owner->addrtype, &(req->owner->addr.ipv4.sin_addr), addr, sizeof(addr)); @@ -40,5 +42,7 @@ ip(struct http_request *req) http_response_header(req, "content-type", "text/plain"); http_response(req, 200, ip, strlen(ip)); + kore_free(addr); + return (KORE_RESULT_OK); } diff --git a/src/jsonip.c b/src/jsonip.c @@ -5,7 +5,7 @@ /* https://www.telize.com */ /* */ /* Created: 2013-08-15 */ -/* Last Updated: 2018-10-04 */ +/* Last Updated: 2018-10-05 */ /* */ /* Telize is released under the BSD 2-Clause license. */ /* See LICENSE file for details. */ @@ -25,11 +25,13 @@ int jsonip(struct http_request *req) { const char *visitor_ip; - char *answer, *callback, *json, *ip, addr[INET6_ADDRSTRLEN]; + char *answer, *callback, *json, *ip, *addr; json_t *output = json_object(); http_populate_get(req); + addr = kore_malloc(INET6_ADDRSTRLEN); + if (req->owner->addrtype == AF_INET) { inet_ntop(req->owner->addrtype, &(req->owner->addr.ipv4.sin_addr), addr, sizeof(addr)); } else { @@ -54,5 +56,7 @@ jsonip(struct http_request *req) http_response_header(req, "content-type", "application/json; charset=utf-8"); http_response(req, 200, answer, strlen(answer)); + kore_free(addr); + return (KORE_RESULT_OK); } diff --git a/src/location.c b/src/location.c @@ -49,7 +49,7 @@ int location(struct http_request *req) { const char *visitor_ip; - char *answer, *callback, *json, *ip, addr[INET6_ADDRSTRLEN]; + char *answer, *callback, *json, *ip, *addr; json_t *output = json_object(); int gai_error, mmdb_error; @@ -61,6 +61,8 @@ location(struct http_request *req) http_populate_get(req); + addr = kore_malloc(INET6_ADDRSTRLEN); + if (req->owner->addrtype == AF_INET) { inet_ntop(req->owner->addrtype, &(req->owner->addr.ipv4.sin_addr), addr, sizeof(addr)); } else { @@ -152,5 +154,7 @@ location(struct http_request *req) http_response_header(req, "content-type", "application/json; charset=utf-8"); http_response(req, 200, answer, strlen(answer)); + kore_free(addr); + return (KORE_RESULT_OK); }