[PATCH] Fix several mem leaks in ldb_index.c, ldb_tdb.c, ldb_search.c

Jeremy Allison jra at samba.org
Fri Jun 15 17:25:15 UTC 2018


On Fri, Jun 15, 2018 at 08:57:28AM +0000, Andrej Gessel via samba-technical wrote:
> Hello list,
> 
> 
> I have found and fixed some mem leaks, at least i think, that these are mem leaks.
> 
> 
> Pipeline[1] on Gitlab is not successful and I don't know why. If i run this test "samba4.ldap.password_lockout.python" locally, it runs successful.
> 
> So please review.
> 
> [1] https://gitlab.com/samba-team/devel/samba/pipelines/23846671

Hi Andrej,

All of these patches look completely correct to me.

RB+.

Can I get a second Team reviewer please ?

The samba4.ldap.password_lockout.python error may be
transient. Once I've gotten a second Team reviewer,
if it fails the autobuild with the same error I'll
look into the problem specifically, but right now
many of the python tests are just unreliable.

Jeremy.

> From 4a334d37ac7eb717fdc7e0cd3b3269de4ac3d7da Mon Sep 17 00:00:00 2001
> From: Andrej Gessel <Andrej.Gessel at janztec.com>
> Date: Thu, 14 Jun 2018 12:19:29 +0200
> Subject: [PATCH] Fix several mem leaks in ldb_index ldb_search ldb_tdb
> 
> Signed-off-by: Andrej Gessel <Andrej.Gessel at janztec.com>
> ---
>  lib/ldb/ldb_tdb/ldb_index.c  | 5 +++++
>  lib/ldb/ldb_tdb/ldb_search.c | 7 ++++---
>  lib/ldb/ldb_tdb/ldb_tdb.c    | 2 ++
>  3 files changed, 11 insertions(+), 3 deletions(-)
> 
> diff --git a/lib/ldb/ldb_tdb/ldb_index.c b/lib/ldb/ldb_tdb/ldb_index.c
> index 04ffbad..d59b4b1 100644
> --- a/lib/ldb/ldb_tdb/ldb_index.c
> +++ b/lib/ldb/ldb_tdb/ldb_index.c
> @@ -416,6 +416,7 @@ normal_index:
>  				      "expected %d for %s",
>  				      version, LTDB_INDEXING_VERSION,
>  				      ldb_dn_get_linearized(dn));
> +			talloc_free(msg);
>  			return LDB_ERR_OPERATIONS_ERROR;
>  		}
>  
> @@ -433,14 +434,17 @@ normal_index:
>  				      "expected %d for %s",
>  				      version, LTDB_GUID_INDEXING_VERSION,
>  				      ldb_dn_get_linearized(dn));
> +			talloc_free(msg);
>  			return LDB_ERR_OPERATIONS_ERROR;
>  		}
>  
>  		if (el->num_values == 0) {
> +			talloc_free(msg);
>  			return LDB_ERR_OPERATIONS_ERROR;
>  		}
>  
>  		if ((el->values[0].length % LTDB_GUID_SIZE) != 0) {
> +			talloc_free(msg);
>  			return LDB_ERR_OPERATIONS_ERROR;
>  		}
>  
> @@ -521,6 +525,7 @@ int ltdb_key_dn_from_idx(struct ldb_module *module,
>  			const int flags = LDB_UNPACK_DATA_FLAG_NO_ATTRS;
>  			struct ldb_message *rec = ldb_msg_new(ldb);
>  			if (rec == NULL) {
> +				TALLOC_FREE(list);
>  				return LDB_ERR_OPERATIONS_ERROR;
>  			}
>  
> diff --git a/lib/ldb/ldb_tdb/ldb_search.c b/lib/ldb/ldb_tdb/ldb_search.c
> index cfc3714..18f8405 100644
> --- a/lib/ldb/ldb_tdb/ldb_search.c
> +++ b/lib/ldb/ldb_tdb/ldb_search.c
> @@ -397,7 +397,7 @@ int ltdb_filter_attrs(TALLOC_CTX *mem_ctx,
>  	/* Shortcuts for the simple cases */
>  	} else if (add_dn && i == 1) {
>  		if (msg_add_distinguished_name(msg2) != 0) {
> -			return -1;
> +			goto failed;
>  		}
>  		*filtered_msg = msg2;
>  		return 0;
> @@ -463,7 +463,7 @@ int ltdb_filter_attrs(TALLOC_CTX *mem_ctx,
>  
>  	if (add_dn) {
>  		if (msg_add_distinguished_name(msg2) != 0) {
> -			return -1;
> +			goto failed;
>  		}
>  	}
>  
> @@ -472,7 +472,7 @@ int ltdb_filter_attrs(TALLOC_CTX *mem_ctx,
>  						struct ldb_message_element,
>  						msg2->num_elements);
>  		if (msg2->elements == NULL) {
> -			return -1;
> +			goto failed;
>  		}
>  	} else {
>  		talloc_free(msg2->elements);
> @@ -483,6 +483,7 @@ int ltdb_filter_attrs(TALLOC_CTX *mem_ctx,
>  
>  	return 0;
>  failed:
> +	TALLOC_FREE(msg2);
>  	return -1;
>  }
>  
> diff --git a/lib/ldb/ldb_tdb/ldb_tdb.c b/lib/ldb/ldb_tdb/ldb_tdb.c
> index 8581604..d119a9f 100644
> --- a/lib/ldb/ldb_tdb/ldb_tdb.c
> +++ b/lib/ldb/ldb_tdb/ldb_tdb.c
> @@ -485,6 +485,7 @@ int ltdb_store(struct ldb_module *module, const struct ldb_message *msg, int flg
>  	}
>  
>  	if (ltdb->read_only) {
> +		talloc_free(tdb_key_ctx);
>  		return LDB_ERR_UNWILLING_TO_PERFORM;
>  	}
>  
> @@ -732,6 +733,7 @@ int ltdb_delete_noindex(struct ldb_module *module,
>  	}
>  
>  	if (ltdb->read_only) {
> +		talloc_free(tdb_key_ctx);
>  		return LDB_ERR_UNWILLING_TO_PERFORM;
>  	}
>  
> -- 
> 2.7.4
> 




More information about the samba-technical mailing list