diff mbox

libselinux: replace all malloc + memset by calloc in android label backend.

Message ID 20170113052026.22069-1-sspatil@google.com (mailing list archive)
State Not Applicable
Headers show

Commit Message

Sandeep Patil Jan. 13, 2017, 5:20 a.m. UTC
Signed-off-by: Sandeep Patil <sspatil@google.com>
---
 libselinux/src/label_backends_android.c | 9 +++------
 1 file changed, 3 insertions(+), 6 deletions(-)

Comments

Stephen Smalley Jan. 13, 2017, 3:48 p.m. UTC | #1
On Thu, 2017-01-12 at 21:20 -0800, Sandeep Patil wrote:
> Signed-off-by: Sandeep Patil <sspatil@google.com>

Thanks, applied.

> ---
>  libselinux/src/label_backends_android.c | 9 +++------
>  1 file changed, 3 insertions(+), 6 deletions(-)
> 
> diff --git a/libselinux/src/label_backends_android.c
> b/libselinux/src/label_backends_android.c
> index 4d6ec86..6442104 100644
> --- a/libselinux/src/label_backends_android.c
> +++ b/libselinux/src/label_backends_android.c
> @@ -200,10 +200,9 @@ static int init(struct selabel_handle *rec,
> const struct selinux_opt *opts,
>  			}
>  
>  			if (NULL == (data->spec_arr =
> -				     malloc(sizeof(spec_t) * data-
> >nspec)))
> +				     calloc(data->nspec,
> sizeof(spec_t))))
>  				goto finish;
>  
> -			memset(data->spec_arr, 0, sizeof(spec_t) *
> data->nspec);
>  			maxnspec = data->nspec;
>  			rewind(fp);
>  		}
> @@ -322,10 +321,9 @@ int selabel_property_init(struct selabel_handle
> *rec,
>  {
>  	struct saved_data *data;
>  
> -	data = (struct saved_data *)malloc(sizeof(*data));
> +	data = (struct saved_data *)calloc(1, sizeof(*data));
>  	if (!data)
>  		return -1;
> -	memset(data, 0, sizeof(*data));
>  
>  	rec->data = data;
>  	rec->func_close = &closef;
> @@ -340,10 +338,9 @@ int selabel_service_init(struct selabel_handle
> *rec,
>  {
>  	struct saved_data *data;
>  
> -	data = (struct saved_data *)malloc(sizeof(*data));
> +	data = (struct saved_data *)calloc(1, sizeof(*data));
>  	if (!data)
>  		return -1;
> -	memset(data, 0, sizeof(*data));
>  
>  	rec->data = data;
>  	rec->func_close = &closef;
diff mbox

Patch

diff --git a/libselinux/src/label_backends_android.c b/libselinux/src/label_backends_android.c
index 4d6ec86..6442104 100644
--- a/libselinux/src/label_backends_android.c
+++ b/libselinux/src/label_backends_android.c
@@ -200,10 +200,9 @@  static int init(struct selabel_handle *rec, const struct selinux_opt *opts,
 			}
 
 			if (NULL == (data->spec_arr =
-				     malloc(sizeof(spec_t) * data->nspec)))
+				     calloc(data->nspec, sizeof(spec_t))))
 				goto finish;
 
-			memset(data->spec_arr, 0, sizeof(spec_t) * data->nspec);
 			maxnspec = data->nspec;
 			rewind(fp);
 		}
@@ -322,10 +321,9 @@  int selabel_property_init(struct selabel_handle *rec,
 {
 	struct saved_data *data;
 
-	data = (struct saved_data *)malloc(sizeof(*data));
+	data = (struct saved_data *)calloc(1, sizeof(*data));
 	if (!data)
 		return -1;
-	memset(data, 0, sizeof(*data));
 
 	rec->data = data;
 	rec->func_close = &closef;
@@ -340,10 +338,9 @@  int selabel_service_init(struct selabel_handle *rec,
 {
 	struct saved_data *data;
 
-	data = (struct saved_data *)malloc(sizeof(*data));
+	data = (struct saved_data *)calloc(1, sizeof(*data));
 	if (!data)
 		return -1;
-	memset(data, 0, sizeof(*data));
 
 	rec->data = data;
 	rec->func_close = &closef;