[SSSD] [PATCH 3/3] Avoid const warnings when deallocating memory

Sumit Bose sbose at redhat.com
Wed Nov 14 16:16:19 UTC 2012


On Wed, Nov 14, 2012 at 09:01:15AM -0500, Simo Sorce wrote:
> In some case we allocate and assign data to a const pointer.
> When we then try to free it we would get a const warning because talloc_free
> accepts a void, not a const void pointer. Use discard_const to avoid the
> warning, it is safe in this case.
> ---
>  src/util/util.h |    2 +-
>  1 files changed, 1 insertions(+), 1 deletions(-)
> 
> diff --git a/src/util/util.h b/src/util/util.h
> index 66bae505df2779dbfc065a09162fd789fef9e835..e85facb92bb4de8d9eeaf97716e1aac252f9b32c 100644
> --- a/src/util/util.h
> +++ b/src/util/util.h
> @@ -228,7 +228,7 @@ errno_t set_debug_file_from_fd(const int fd);
>  #define FLAGS_PID_FILE 0x0004
>  
>  #ifndef talloc_zfree
> -#define talloc_zfree(ptr) do { talloc_free(ptr); ptr = NULL; } while(0)
> +#define talloc_zfree(ptr) do { talloc_free(discard_const(ptr)); ptr = NULL; } while(0)

I wonder if it would be cleaner to add a talloc_zfree_const() or similar
which can be used in places where it is safe to suppress the warning.
At other place the warning might be useful to discover e.g. some
copy-and-paste errors.

bye,
Sumit

>  #endif
>  
>  #ifndef discard_const_p
> -- 
> 1.7.1
> 
> _______________________________________________
> sssd-devel mailing list
> sssd-devel at lists.fedorahosted.org
> https://lists.fedorahosted.org/mailman/listinfo/sssd-devel



More information about the sssd-devel mailing list