Commit f42de62a authored by Max Kellermann's avatar Max Kellermann

added xfree() which takes a const pointer

Unfortunately, the C standard postulates that the argument to free() must be non-const. This does not makes sense, and virtually prevents every pointer which must be freed at some time to be non-const. Use the deconst hack (sorry for that) to allow us to free constant pointers.
parent 8811c0e0
......@@ -76,6 +76,19 @@ mpd_malloc void *xrealloc(void *ptr, size_t size);
mpd_malloc void *xcalloc(size_t nmemb, size_t size);
/**
* free a const pointer - unfortunately free() expects a non-const
* pointer, for whatever reason
*/
static inline void xfree(const void *p)
{
union {
const void *in;
void *out;
} deconst = { .in = p };
free(deconst.out);
}
char *parsePath(char *path);
int set_nonblocking(int fd);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment