Skip to content

Commit

Permalink
Merge pull request #37 from maxmind/dave/fix-missing-free
Browse files Browse the repository at this point in the history
Fix a memory leak reported in #36
  • Loading branch information
oschwald committed Jul 21, 2014
2 parents 1d54c09 + ddb2b42 commit 21396b7
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 6 deletions.
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -12,6 +12,7 @@
/bin/country_lookup
/bin/mmdbdump
/bin/mmdblookup
/compile
/config.*
/configure
/depcomp
Expand Down
7 changes: 7 additions & 0 deletions Changes.md
@@ -1,3 +1,10 @@
## 0.5.6

* There was a leak in the `MMDB_open()` sub when it was called against a file
which did not contain any MMDB metadata. Reported by Federico
G. Schwindt. GitHub issue #36.


## 0.5.5 - 2014-03-11

* The previous tarball failed to compile because it was missing the
Expand Down
12 changes: 7 additions & 5 deletions src/maxminddb.c
Expand Up @@ -250,6 +250,7 @@ int MMDB_open(const char *const filename, uint32_t flags, MMDB_s *const mmdb)
uint32_t metadata_size = 0;
const uint8_t *metadata = find_metadata(file_content, size, &metadata_size);
if (NULL == metadata) {
free_mmdb_struct(mmdb);
return MMDB_INVALID_METADATA_ERROR;
}

Expand Down Expand Up @@ -1532,15 +1533,16 @@ LOCAL void free_descriptions_metadata(MMDB_s *mmdb)
if (NULL != mmdb->metadata.description.descriptions[i]) {
if (NULL !=
mmdb->metadata.description.descriptions[i]->language) {
free((char *)mmdb->metadata.description.descriptions[i]
->
language);
free(
(char *)mmdb->metadata.description.descriptions[i]->
language);
}

if (NULL !=
mmdb->metadata.description.descriptions[i]->description) {
free((char *)mmdb->metadata.description.
descriptions[i]->description);
free(
(char *)mmdb->metadata.description.descriptions[i]->
description);
}
free(mmdb->metadata.description.descriptions[i]);
}
Expand Down
2 changes: 1 addition & 1 deletion t/maxminddb_test_helper.c
Expand Up @@ -169,7 +169,7 @@ MMDB_lookup_result_s lookup_sockaddr_ok(MMDB_s *mmdb, const char *ip,
if (gai_error == 0) {
result = MMDB_lookup_sockaddr(mmdb, addresses->ai_addr, &mmdb_error);
}
if ( addresses != NULL ) {
if (addresses != NULL) {
freeaddrinfo(addresses);
}

Expand Down

0 comments on commit 21396b7

Please sign in to comment.