From 90847fc8818836a296e9d500725c0eb154a4d3c5 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Sat, 26 Aug 2006 06:25:57 +0000 Subject: Replace strdup and {c,re,m}alloc with x* variants to check for OOM errors I'm checking for zero-size allocations and assert()-ing them, so we can more easily get backtraces and debug problems, but we'll also allow -DNDEBUG people to live on the edge if they wish. We do not rely on errno when checking for OOM errors because some implementations of malloc do not set it, and malloc is commonly overridden by userspace wrappers. I've spent some time looking through the source and didn't find any obvious places where we would explicitly allocate 0 bytes, so we shouldn't trip any of those assertions. We also avoid allocating zero bytes because C libraries don't handle this consistently (some return NULL, some not); and it's dangerous either way. git-svn-id: https://svn.musicpd.org/mpd/trunk@4690 09075e82-0dd4-0310-85a5-a0d7c8717e4f --- src/utils.h | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'src/utils.h') diff --git a/src/utils.h b/src/utils.h index 28b2845c6..ae66e3be2 100644 --- a/src/utils.h +++ b/src/utils.h @@ -20,6 +20,7 @@ #define UTILS_H #include "../config.h" +#include "gcc.h" #include #include @@ -73,4 +74,12 @@ static inline ssize_t xwrite(int fd, const void *buf, size_t len) } } +mpd_malloc char *xstrdup(const char *s); + +mpd_malloc void *xmalloc(size_t size); + +mpd_malloc void *xrealloc(void *ptr, size_t size); + +mpd_malloc void *xcalloc(size_t nmemb, size_t size); + #endif -- cgit v1.2.3