[SCM] NSS Wrapper Repository - branch master updated

Michael Adam obnox at samba.org
Fri Nov 6 07:18:01 UTC 2015


The branch, master has been updated
       via  dcc2c37 nwrap: Fix memory leak in nwrap_he_unload()
       via  7a7bf7b nwrap: Rename cont to vector in nwrap_vector_add_item()
       via  c3a8b23 nwrap: Fix memory leak inside nwrap_getaddrinfo()
       via  c0d418c nwrap: Use nwrap_vector_foreach instead of for loop
       via  04fcf29 nwrap: Fix memory leak when getline() is used.
      from  99af0e0 tests: add test for merging with empty vectors left and right.

https://git.samba.org/?p=nss_wrapper.git;a=shortlog;h=master


- Log -----------------------------------------------------------------
commit dcc2c378276a9059336d521a4b8f8d1fa64d6368
Author: Robin Hack <hack.robin at gmail.com>
Date:   Thu Oct 8 15:00:33 2015 +0200

    nwrap: Fix memory leak in nwrap_he_unload()
    
    Signed-off-by: Robin Hack <hack.robin at gmail.com>
    Reviewed-by: Andreas Schneider <asn at samba.org>
    Reviewed-by: Michael Adam <obnox at samba.org>

commit 7a7bf7bffa7daead410948b6c1e13a0cab3e5de8
Author: Robin Hack <hack.robin at gmail.com>
Date:   Thu Oct 8 14:09:11 2015 +0200

    nwrap: Rename cont to vector in nwrap_vector_add_item()
    
    Signed-off-by: Robin Hack <hack.robin at gmail.com>
    Reviewed-by: Andreas Schneider <asn at samba.org>
    Reviewed-by: Michael Adam <obnox at samba.org>

commit c3a8b23e64ad641754e8c09fea407c4370703024
Author: Robin Hack <hack.robin at gmail.com>
Date:   Thu Oct 8 14:02:56 2015 +0200

    nwrap: Fix memory leak inside nwrap_getaddrinfo()
    
    Memory leak was introduced by deep copy code.
    Item ai_tmp->ai_addr should not have deep copy.
    
    Signed-off-by: Robin Hack <hack.robin at gmail.com>
    Reviewed-by: Andreas Schneider <asn at samba.org>
    Reviewed-by: Michael Adam <obnox at samba.org>

commit c0d418ce0b3f494eb09d0d8aff8c965207b80411
Author: Robin Hack <hack.robin at gmail.com>
Date:   Thu Oct 8 14:00:38 2015 +0200

    nwrap: Use nwrap_vector_foreach instead of for loop
    
    Replace for loop by nwrap_vector_foreach in nwrap_lines_unload().
    
    Signed-off-by: Robin Hack <hack.robin at gmail.com>
    Reviewed-by: Andreas Schneider <asn at samba.org>
    Reviewed-by: Michael Adam <obnox at samba.org>

commit 04fcf2958abade59e4fb0fe5f8eb0f47cf6ff64b
Author: Robin Hack <hack.robin at gmail.com>
Date:   Thu Oct 8 11:36:33 2015 +0200

    nwrap: Fix memory leak when getline() is used.
    
    getline() allocates memory even if return code is < 0.
    
    Signed-off-by: Robin Hack <hack.robin at gmail.com>
    Reviewed-by: Andreas Schneider <asn at samba.org>
    Reviewed-by: Michael Adam <obnox at samba.org>

-----------------------------------------------------------------------

Summary of changes:
 src/nss_wrapper.c | 35 +++++++++++++++++++----------------
 1 file changed, 19 insertions(+), 16 deletions(-)


Changeset truncated at 500 lines:

diff --git a/src/nss_wrapper.c b/src/nss_wrapper.c
index bf51ec2..3496162 100644
--- a/src/nss_wrapper.c
+++ b/src/nss_wrapper.c
@@ -622,32 +622,32 @@ static inline bool nwrap_vector_init(struct nwrap_vector *const vector)
 	return true;
 }
 
-static bool nwrap_vector_add_item(struct nwrap_vector *cont, void *const item)
+static bool nwrap_vector_add_item(struct nwrap_vector *vector, void *const item)
 {
-	assert (cont != NULL);
+	assert (vector != NULL);
 
-	if (cont->items == NULL) {
-		nwrap_vector_init(cont);
+	if (vector->items == NULL) {
+		nwrap_vector_init(vector);
 	}
 
-	if (cont->count == cont->capacity) {
+	if (vector->count == vector->capacity) {
 		/* Items array _MUST_ be NULL terminated because it's passed
 		 * as result to caller which expect NULL terminated array from libc.
 		 */
-		void **items = realloc(cont->items, sizeof(void *) * ((cont->capacity * 2) + 1));
+		void **items = realloc(vector->items, sizeof(void *) * ((vector->capacity * 2) + 1));
 		if (items == NULL) {
 			return false;
 		}
-		cont->items = items;
+		vector->items = items;
 
 		/* Don't count ending NULL to capacity */
-		cont->capacity *= 2;
+		vector->capacity *= 2;
 	}
 
-	cont->items[cont->count] = item;
+	vector->items[vector->count] = item;
 
-	cont->count += 1;
-	cont->items[cont->count] = NULL;
+	vector->count += 1;
+	vector->items[vector->count] = NULL;
 
 	return true;
 }
@@ -928,12 +928,13 @@ static void *_nwrap_load_lib_function(enum nwrap_lib lib, const char *fn_name)
 static void nwrap_lines_unload(struct nwrap_cache *const nwrap)
 {
 	size_t p;
-	for (p = 0; p < nwrap->lines.count; p++) {
+	void *item;
+	nwrap_vector_foreach(item, nwrap->lines, p) {
 		/* Maybe some vectors were merged ... */
-		SAFE_FREE(nwrap->lines.items[p]);
+		SAFE_FREE(item);
 	}
 	SAFE_FREE(nwrap->lines.items);
-	nwrap->lines.count = 0;
+	ZERO_STRUCTP(&nwrap->lines);
 }
 
 /*
@@ -1705,6 +1706,7 @@ static bool nwrap_parse_file(struct nwrap_cache *nwrap)
 	do {
 		n = getline(&line, &len, nwrap->fp);
 		if (n < 0) {
+			SAFE_FREE(line);
 			if (feof(nwrap->fp)) {
 				break;
 			}
@@ -2852,6 +2854,7 @@ static void nwrap_he_unload(struct nwrap_cache *nwrap)
 
 	nwrap_vector_foreach (ed, nwrap_he->entdata, i)
 	{
+		SAFE_FREE(ed->nwrap_addrdata.items);
 		SAFE_FREE(ed->ht.h_aliases);
 		SAFE_FREE(ed);
 	}
@@ -5152,8 +5155,8 @@ static int nwrap_getaddrinfo(const char *node,
 				ai_tmp->ai_canonname =
 					strdup(ai_head->ai_canonname);
 			}
-			ai_tmp->ai_addr = malloc(sizeof(struct sockaddr));
-			memcpy(ai_tmp->ai_addr, ai_head, sizeof(struct sockaddr));
+			/* ai_head should point inside hints. */
+			ai_tmp->ai_addr = ai_head->ai_addr;
 
 			if (ai_head->ai_flags == 0) {
 				ai_tmp->ai_flags = hints->ai_flags;


-- 
NSS Wrapper Repository



More information about the samba-cvs mailing list