wget-dev
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Wget-dev] wget2 | Make wget allocation functions overridable functi


From: Darshit Shah
Subject: Re: [Wget-dev] wget2 | Make wget allocation functions overridable function pointers (d5e648e8)
Date: Tue, 18 Jun 2019 21:10:30 +0000



Darshit Shah started a new discussion on include/wget/wget.h: 
https://gitlab.com/gnuwget/wget2/commit/d5e648e82bf41da724ff3b613a60b6dd9493d80a#note_182776610

>       wget_list_browse(const wget_list_t *list, wget_list_browse_t browse, 
> void *context) G_GNUC_WGET_NONNULL((2));
>  
> -/*
> - * Memory allocation routines
> +/**
> + * \ingroup libwget-xalloc
> + *
> + * Memory allocation function pointers
> + * @{
>   */
>  
> -// I try to never leave freed pointers hanging around
> +// Don't leave freed pointers hanging around
>  #define wget_xfree(a) do { if (a) { wget_free((void *)(a)); a=NULL; } } 
> while (0)
>  
> -typedef void *(*wget_oom_callback_t)(int size);

So, if I understand this correctly, we no longer have any OOM callback 
function. 

What happens when the user defines a malloc function, but:

1. It returns a `NULL`. The library might de-reference a null-ptr and segfault
2. It returns a smaller chunk of memory

In general, we can assume that 2 never happens and if it does, it is a gross 
violation by the client.
However, I don't think causing a segfault in the library due to 1 is a good 
idea. We still need to check for NULL and then propagate an error back to the 
caller.
Maybe, we can have:

```
# define _wget_malloc(size) do { \
  void *p = wget_malloc(size); \
  if (!p) return WGET_ERR_OOM; \
} while(0);
```

The syntax for the macro might be incorrect, but we can use such a macro 
throughout the library and change the functions prototypes where needed. WDYT?

-- 
Reply to this email directly or view it on GitLab: 
https://gitlab.com/gnuwget/wget2/commit/d5e648e82bf41da724ff3b613a60b6dd9493d80a#note_182776610
You're receiving this email because of your account on gitlab.com.




reply via email to

[Prev in Thread] Current Thread [Next in Thread]