diff mbox series

[RFC,v2,09/27] libselinux: simplify zeroing allocation

Message ID 20230814132025.45364-10-cgzones@googlemail.com (mailing list archive)
State Accepted
Commit 92b1e5b660b6
Delegated to: Petr Lautrbach
Headers show
Series libselinux: rework selabel_file(5) database | expand

Commit Message

Christian Göttsche Aug. 14, 2023, 1:20 p.m. UTC
Merge malloc(3) plus memset(3) call into calloc(3).

Signed-off-by: Christian Göttsche <cgzones@googlemail.com>
---
 libselinux/src/label_file.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)

Comments

James Carter Oct. 2, 2023, 8:36 p.m. UTC | #1
On Mon, Aug 14, 2023 at 9:41 AM Christian Göttsche
<cgzones@googlemail.com> wrote:
>
> Merge malloc(3) plus memset(3) call into calloc(3).
>
> Signed-off-by: Christian Göttsche <cgzones@googlemail.com>

Acked-by: James Carter <jwcart2@gmail.com>

> ---
>  libselinux/src/label_file.c | 6 ++----
>  1 file changed, 2 insertions(+), 4 deletions(-)
>
> diff --git a/libselinux/src/label_file.c b/libselinux/src/label_file.c
> index 5ac23e1f..b9be1c9d 100644
> --- a/libselinux/src/label_file.c
> +++ b/libselinux/src/label_file.c
> @@ -716,10 +716,9 @@ static int selabel_subs_init(const char *path, struct selabel_digest *digest,
>                 if (! *dst)
>                         continue;
>
> -               sub = malloc(sizeof(*sub));
> +               sub = calloc(1, sizeof(*sub));
>                 if (! sub)
>                         goto err;
> -               memset(sub, 0, sizeof(*sub));
>
>                 sub->src = strdup(src);
>                 if (! sub->src)
> @@ -1357,10 +1356,9 @@ int selabel_file_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;
> --
> 2.40.1
>
James Carter Oct. 12, 2023, 5:53 p.m. UTC | #2
On Mon, Oct 2, 2023 at 4:36 PM James Carter <jwcart2@gmail.com> wrote:
>
> On Mon, Aug 14, 2023 at 9:41 AM Christian Göttsche
> <cgzones@googlemail.com> wrote:
> >
> > Merge malloc(3) plus memset(3) call into calloc(3).
> >
> > Signed-off-by: Christian Göttsche <cgzones@googlemail.com>
>
> Acked-by: James Carter <jwcart2@gmail.com>
>
Merged.
Thanks,
Jim

> > ---
> >  libselinux/src/label_file.c | 6 ++----
> >  1 file changed, 2 insertions(+), 4 deletions(-)
> >
> > diff --git a/libselinux/src/label_file.c b/libselinux/src/label_file.c
> > index 5ac23e1f..b9be1c9d 100644
> > --- a/libselinux/src/label_file.c
> > +++ b/libselinux/src/label_file.c
> > @@ -716,10 +716,9 @@ static int selabel_subs_init(const char *path, struct selabel_digest *digest,
> >                 if (! *dst)
> >                         continue;
> >
> > -               sub = malloc(sizeof(*sub));
> > +               sub = calloc(1, sizeof(*sub));
> >                 if (! sub)
> >                         goto err;
> > -               memset(sub, 0, sizeof(*sub));
> >
> >                 sub->src = strdup(src);
> >                 if (! sub->src)
> > @@ -1357,10 +1356,9 @@ int selabel_file_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;
> > --
> > 2.40.1
> >
diff mbox series

Patch

diff --git a/libselinux/src/label_file.c b/libselinux/src/label_file.c
index 5ac23e1f..b9be1c9d 100644
--- a/libselinux/src/label_file.c
+++ b/libselinux/src/label_file.c
@@ -716,10 +716,9 @@  static int selabel_subs_init(const char *path, struct selabel_digest *digest,
 		if (! *dst)
 			continue;
 
-		sub = malloc(sizeof(*sub));
+		sub = calloc(1, sizeof(*sub));
 		if (! sub)
 			goto err;
-		memset(sub, 0, sizeof(*sub));
 
 		sub->src = strdup(src);
 		if (! sub->src)
@@ -1357,10 +1356,9 @@  int selabel_file_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;