#define MMDBR_STRINGIFY_S(s) #s
#define OUT_BUF_SIZE 65536
+// Uncomment to enable slow lookups. Only useful on Windows for now.
+// #define MMDB_DEBUG_SLOW 1
+
+#ifdef MMDB_DEBUG_SLOW
+#ifdef _WIN32
+#include <Windows.h>
+#endif
+#endif
+
static const char *co_iso_key[] = {"country", "iso_code", NULL};
static const char *co_name_key[] = {"country", "names", "en", NULL};
static const char *ci_name_key[] = {"city", "names", "en", NULL};
{
char addr_str[MAX_ADDR_LEN+1];
size_t mmdb_count = 0;
- MMDB_s *mmdbs = NULL;
+ MMDB_s *mmdbs = NULL, *new_mmdbs;
int mmdb_err;
char *out_buf = (char *) malloc(OUT_BUF_SIZE);
fprintf(stdout, "db.%zd.status: ", mmdb_count);
if (mmdb_err == MMDB_SUCCESS) {
mmdb_count++;
- mmdbs = (MMDB_s *) realloc(mmdbs, mmdb_count * sizeof(MMDB_s));
- if (mmdbs == NULL) {
+ new_mmdbs = (MMDB_s *) realloc(mmdbs, mmdb_count * sizeof(MMDB_s));
+ if (new_mmdbs == NULL) {
+ free(mmdbs);
fprintf(stdout, "ERROR out of memory\n");
return 1;
}
+ mmdbs = new_mmdbs;
mmdbs[mmdb_count - 1] = try_mmdb;
fprintf(stdout, "OK\n");
fprintf(stdout, "db.%zd.type: %s\n", mmdb_count, mmdbs[mmdb_count - 1].metadata.database_type);
}
fprintf(stdout, "[%s]\n", addr_str);
+#ifdef MMDB_DEBUG_SLOW
+#ifdef _WIN32
+ Sleep(1000);
+#endif
+#endif
+
for (size_t mmdb_idx = 0; mmdb_idx < mmdb_count; mmdb_idx++) {
fprintf(stdout, "# %s\n", mmdbs[mmdb_idx].metadata.database_type);
MMDB_lookup_result_s result = MMDB_lookup_string(&mmdbs[mmdb_idx], addr_str, &gai_err, &mmdb_err);