[SCM] NSS Wrapper Repository - branch master updated
Andreas Schneider
asn at samba.org
Thu Nov 19 08:39:49 UTC 2015
The branch, master has been updated
via 18c1d17 nwrap: Cleanup shadow getspnam() memory
via 17a4fa5 nwrap: fix leaking the entlists
via aa5aa9e nwrap: catch error to add item to vector in nwrap_he_parse_line()
via 1797373 nwrap: rename nwrap_he.entdata to nwrap_he.entries
via 21c10b8 nwrap: remove unused member list from struct nwrap_he
via 57b7b9d nwrap: Small code shift in nwrap_ed_inventarize_add_to_existing()
via 72ecc23 tests: Fix memory leaks in getaddrinfo test
from 174f7a1 nwrap: Cast max_hostents to avoid warnings
https://git.samba.org/?p=nss_wrapper.git;a=shortlog;h=master
- Log -----------------------------------------------------------------
commit 18c1d1723a7364419eb6f2cb8de1238848f68f16
Author: Andreas Schneider <asn at samba.org>
Date: Thu Nov 19 09:02:46 2015 +0100
nwrap: Cleanup shadow getspnam() memory
Signed-off-by: Andreas Schneider <asn at samba.org>
Signed-off-by: Michael Adam <obnox at samba.org>
commit 17a4fa5d1ec7b79eea7da2967fe3a48aaa63a12c
Author: Michael Adam <obnox at samba.org>
Date: Thu Nov 19 01:00:16 2015 +0100
nwrap: fix leaking the entlists
Track the list heads in a vector in the newrap_he_global
struct and free the structures upon nwrap_he_unload.
Signed-off-by: Michael Adam <obnox at samba.org>
Reviewed-by: Andreas Schneider <asn at samba.org>
commit aa5aa9e8eed87b52ac1a85698d587c1e0ecd7a19
Author: Michael Adam <obnox at samba.org>
Date: Thu Nov 19 00:34:54 2015 +0100
nwrap: catch error to add item to vector in nwrap_he_parse_line()
Signed-off-by: Michael Adam <obnox at samba.org>
Reviewed-by: Andreas Schneider <asn at samba.org>
commit 1797373faeee0bdc60bc02ad75179bc3837f7269
Author: Michael Adam <obnox at samba.org>
Date: Thu Nov 19 00:30:17 2015 +0100
nwrap: rename nwrap_he.entdata to nwrap_he.entries
That's what is is the list of entries. In the guise
nwrap_entdata structures but the code reads more
naturally this way.
Signed-off-by: Michael Adam <obnox at samba.org>
Reviewed-by: Andreas Schneider <asn at samba.org>
commit 21c10b80fa9bca3806426720c19937795f01a829
Author: Michael Adam <obnox at samba.org>
Date: Thu Nov 19 00:24:14 2015 +0100
nwrap: remove unused member list from struct nwrap_he
Signed-off-by: Michael Adam <obnox at samba.org>
Reviewed-by: Andreas Schneider <asn at samba.org>
commit 57b7b9d14cbdc258c6123334d6ff93931b675283
Author: Robin Hack <hack.robin at gmail.com>
Date: Mon Nov 16 23:38:51 2015 +0100
nwrap: Small code shift in nwrap_ed_inventarize_add_to_existing()
Allocate memory only when necessary.
Signed-off-by: Robin Hack <hack.robin at gmail.com>
Reviewed-by: Michael Adam <obnox at samba.org>
Reviewed-by: Andreas Schneider <asn at samba.org>
commit 72ecc23042859c0626943afff4901b5b9dcb6316
Author: Andreas Schneider <asn at samba.org>
Date: Mon Nov 16 20:43:00 2015 +0100
tests: Fix memory leaks in getaddrinfo test
Signed-off-by: Andreas Schneider <asn at samba.org>
Reviewed-by: Michael Adam <obnox at samba.org>
-----------------------------------------------------------------------
Summary of changes:
src/nss_wrapper.c | 75 +++++++++++++++++++++++++++++++++++++-----------
tests/test_getaddrinfo.c | 12 ++++++++
2 files changed, 71 insertions(+), 16 deletions(-)
Changeset truncated at 500 lines:
diff --git a/src/nss_wrapper.c b/src/nss_wrapper.c
index a8cbc22..914cd26 100644
--- a/src/nss_wrapper.c
+++ b/src/nss_wrapper.c
@@ -770,8 +770,8 @@ struct nwrap_entlist {
struct nwrap_he {
struct nwrap_cache *cache;
- struct nwrap_entdata *list;
- struct nwrap_vector entdata;
+ struct nwrap_vector entries;
+ struct nwrap_vector lists;
int num;
int idx;
@@ -2576,6 +2576,7 @@ static bool nwrap_ed_inventarize_add_new(char *const h_name,
ENTRY e;
ENTRY *p;
struct nwrap_entlist *el;
+ bool ok;
if (h_name == NULL) {
NWRAP_LOG(NWRAP_LOG_ERROR, "h_name NULL - can't add");
@@ -2596,6 +2597,13 @@ static bool nwrap_ed_inventarize_add_new(char *const h_name,
return false;
}
+ ok = nwrap_vector_add_item(&(nwrap_he_global.lists), (void *)el);
+ if (!ok) {
+ NWRAP_LOG(NWRAP_LOG_ERROR,
+ "Failed to add list entry to vector.");
+ return false;
+ }
+
return true;
}
@@ -2610,21 +2618,20 @@ static bool nwrap_ed_inventarize_add_to_existing(struct nwrap_entdata *const ed,
return false;
}
- el_new = nwrap_entlist_init(ed);
- if (el_new == NULL) {
- return false;
- }
for (cursor = el; cursor->next != NULL; cursor = cursor->next)
{
if (cursor->ed == ed) {
- free(el_new);
return false;
}
}
if (cursor->ed == ed) {
- free(el_new);
+ return false;
+ }
+
+ el_new = nwrap_entlist_init(ed);
+ if (el_new == NULL) {
return false;
}
@@ -2759,8 +2766,13 @@ static bool nwrap_he_parse_line(struct nwrap_cache *nwrap, char *line)
}
ip = i;
- nwrap_vector_add_item(&(ed->nwrap_addrdata),
- (void *const)ed->addr.host_addr);
+ ok = nwrap_vector_add_item(&(ed->nwrap_addrdata),
+ (void *const)ed->addr.host_addr);
+ if (!ok) {
+ NWRAP_LOG(NWRAP_LOG_ERROR, "Unable to add addrdata to vector");
+ free(ed);
+ return false;
+ }
ed->ht.h_addr_list = nwrap_vector_head(&ed->nwrap_addrdata);
p++;
@@ -2846,7 +2858,12 @@ static bool nwrap_he_parse_line(struct nwrap_cache *nwrap, char *line)
aliases_count += 1;
}
- nwrap_vector_add_item(&(nwrap_he->entdata), (void *const)ed);
+ ok = nwrap_vector_add_item(&(nwrap_he->entries), (void *const)ed);
+ if (!ok) {
+ NWRAP_LOG(NWRAP_LOG_ERROR, "Unable to add entry to vector");
+ free(ed);
+ return false;
+ }
ed->aliases_count = aliases_count;
/* Inventarize item */
@@ -2869,16 +2886,30 @@ static void nwrap_he_unload(struct nwrap_cache *nwrap)
struct nwrap_he *nwrap_he =
(struct nwrap_he *)nwrap->private_data;
struct nwrap_entdata *ed;
+ struct nwrap_entlist *el;
size_t i;
- nwrap_vector_foreach (ed, nwrap_he->entdata, i)
+ nwrap_vector_foreach (ed, nwrap_he->entries, i)
{
SAFE_FREE(ed->nwrap_addrdata.items);
SAFE_FREE(ed->ht.h_aliases);
SAFE_FREE(ed);
}
- SAFE_FREE(nwrap_he->entdata.items);
- nwrap_he->entdata.count = nwrap_he->entdata.capacity = 0;
+ SAFE_FREE(nwrap_he->entries.items);
+ nwrap_he->entries.count = nwrap_he->entries.capacity = 0;
+
+ nwrap_vector_foreach(el, nwrap_he->lists, i)
+ {
+ while (el != NULL) {
+ struct nwrap_entlist *el_next;
+
+ el_next = el->next;
+ SAFE_FREE(el);
+ el = el_next;
+ }
+ }
+ SAFE_FREE(nwrap_he->lists.items);
+ nwrap_he->lists.count = nwrap_he->lists.capacity = 0;
nwrap_he->num = 0;
nwrap_he->idx = 0;
@@ -3632,7 +3663,7 @@ static struct hostent *nwrap_files_gethostbyaddr(const void *addr,
return NULL;
}
- nwrap_vector_foreach(ed, nwrap_he_global.entdata, i)
+ nwrap_vector_foreach(ed, nwrap_he_global.entries, i)
{
he = &(ed->ht);
if (he->h_addrtype != type) {
@@ -3710,7 +3741,7 @@ static struct hostent *nwrap_files_gethostent(void)
return NULL;
}
- he = &((struct nwrap_entdata *)nwrap_he_global.entdata.items[nwrap_he_global.idx++])->ht;
+ he = &((struct nwrap_entdata *)nwrap_he_global.entries.items[nwrap_he_global.idx++])->ht;
NWRAP_LOG(NWRAP_LOG_DEBUG, "return hosts[%s]", he->h_name);
@@ -5520,6 +5551,18 @@ void nwrap_destructor(void)
nwrap_pw_global.num = 0;
}
+ if (nwrap_sp_global.cache != NULL) {
+ struct nwrap_cache *c = nwrap_sp_global.cache;
+
+ nwrap_files_cache_unload(c);
+ if (c->fd >= 0) {
+ fclose(c->fp);
+ c->fd = -1;
+ }
+
+ nwrap_he_global.num = 0;
+ }
+
if (nwrap_he_global.cache != NULL) {
struct nwrap_cache *c = nwrap_he_global.cache;
diff --git a/tests/test_getaddrinfo.c b/tests/test_getaddrinfo.c
index ea3e995..b200275 100644
--- a/tests/test_getaddrinfo.c
+++ b/tests/test_getaddrinfo.c
@@ -104,18 +104,26 @@ static void test_nwrap_getaddrinfo_samba(void **state)
rc = getaddrinfo("127.0.0.21", NULL, &hints, &res);
assert_int_equal(rc, 0);
assert_non_null(res);
+ freeaddrinfo(res);
+ res = NULL;
rc = getaddrinfo("samba.example.com", NULL, &hints, &res);
assert_int_equal(rc, 0);
assert_non_null(res);
+ freeaddrinfo(res);
+ res = NULL;
rc = getaddrinfo("localdc", NULL, &hints, &res);
assert_int_equal(rc, 0);
assert_non_null(res);
+ freeaddrinfo(res);
+ res = NULL;
rc = getaddrinfo("localdc.samba.example.com", NULL, &hints, &res);
assert_int_equal(rc, 0);
assert_non_null(res);
+ freeaddrinfo(res);
+ res = NULL;
rc = getaddrinfo("fd00:0000:0000:0000:0000:0000:5357:5f15", NULL, &hints, &res);
assert_int_equal(rc, 0);
@@ -527,6 +535,8 @@ static void test_nwrap_getaddrinfo_flags_ai_numericserv(void **state)
rc = getaddrinfo(NULL, "80", &hints, &res);
assert_int_equal(rc, 0);
+ freeaddrinfo(res);
+ res = NULL;
/* Crippled input */
rc = getaddrinfo(NULL, "80a1", &hints, &res);
@@ -541,6 +551,8 @@ static void test_nwrap_getaddrinfo_flags_ai_numericserv(void **state)
rc = getaddrinfo("magrathea.galaxy.site", "80", &hints, &res);
assert_int_equal(rc, 0);
+ freeaddrinfo(res);
+ res = NULL;
/* Crippled input */
rc = getaddrinfo("magrathea.galaxy.site", "80a1", &hints, &res);
--
NSS Wrapper Repository
More information about the samba-cvs
mailing list