Skip to content

Commit

Permalink
Fix memory leaks with config's storage_root and hostname fields;
Browse files Browse the repository at this point in the history
use freeaddrinfo() on result from getaddrinfo().
  • Loading branch information
jcnelson committed Aug 28, 2014
1 parent 6193ca1 commit 978f6bf
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions libsyndicate/libsyndicate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ static int md_init_server_info( struct md_syndicate_conf* c ) {
if( rc != 0 ) {
// could not get addr info
errorf("getaddrinfo(%s): %s\n", hostname, gai_strerror( rc ) );
freeaddrinfo( result );
return -abs(rc);
}

Expand All @@ -63,12 +64,15 @@ static int md_init_server_info( struct md_syndicate_conf* c ) {
rc = getnameinfo( result->ai_addr, result->ai_addrlen, hn, HOST_NAME_MAX, NULL, 0, NI_NAMEREQD );
if( rc != 0 ) {
errorf("getnameinfo: %s\n", gai_strerror( rc ) );
freeaddrinfo( result );
return -abs(rc);
}

dbprintf("canonical hostname is %s\n", hn);

c->hostname = strdup(hn);

freeaddrinfo( result );
#else
c->hostname = strdup("localhost");
#endif
Expand Down Expand Up @@ -614,6 +618,8 @@ int md_free_conf( struct md_syndicate_conf* conf ) {
(void*)conf->volume_pubkey,
(void*)conf->syndicate_pubkey,
(void*)conf->local_sd_dir,
(void*)conf->hostname,
(void*)conf->storage_root,
(void*)conf
};

Expand Down

0 comments on commit 978f6bf

Please sign in to comment.