[PATCH 08/13] securityselinuxhelper: Use g_new0() instead of malloc()+memset() combo
Claudio Fontana
cfontana at suse.de
Thu Aug 3 11:29:09 UTC 2023
On 8/3/23 12:36, Michal Privoznik wrote:
> Inside of securityselinuxhelper we still use malloc() +
> memset(.., 0, ...) combo. Convert it to g_new0().
>
> Signed-off-by: Michal Privoznik <mprivozn at redhat.com>
I don't think it is a good idea to mix Glib g_new, g_free etc with malloc, calloc, free.
If you go with g_new0 here, imo you need to also change the calls to free() to g_free.
The alternative is to use calloc instead, then you could leave the existing free calls alone.
Ciao,
Claudio
> ---
> tests/securityselinuxhelper.c | 5 ++---
> 1 file changed, 2 insertions(+), 3 deletions(-)
>
> diff --git a/tests/securityselinuxhelper.c b/tests/securityselinuxhelper.c
> index c32c90c17e..797f090a7e 100644
> --- a/tests/securityselinuxhelper.c
> +++ b/tests/securityselinuxhelper.c
> @@ -173,9 +173,8 @@ int getfilecon_raw(const char *path, char **con)
> }
> if (len < 0)
> return -1;
> - if (!(constr = malloc(len+1)))
> - return -1;
> - memset(constr, 0, len);
> +
> + constr = g_new0(char, len + 1);
> if (getxattr(path, "user.libvirt.selinux", constr, len) < 0) {
> free(constr);
> return -1;
More information about the libvir-list
mailing list