Omit compiler warning by sticking to RAII

Resolve gcc 4.9.0 20140507 warnings about uninitialized 'ptr' when
using -Wmaybe-uninitialized.  The first two cases appears appear
to be legitimate but not the second two.  In general this is a
good practice so they are all initialized.

Signed-off-by: Marcel Huber <marcelhuberfoo@gmail.com>
Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov>
Closes #2345
This commit is contained in:
Marcel Huber 2014-05-21 11:17:23 +02:00 committed by Brian Behlendorf
parent 5f3c101b8f
commit 58bd7ad060

View File

@ -82,7 +82,7 @@ typedef struct umem_cache {
static inline void * static inline void *
umem_alloc(size_t size, int flags) umem_alloc(size_t size, int flags)
{ {
void *ptr; void *ptr = NULL;
do { do {
ptr = malloc(size); ptr = malloc(size);
@ -94,8 +94,8 @@ umem_alloc(size_t size, int flags)
static inline void * static inline void *
umem_alloc_aligned(size_t size, size_t align, int flags) umem_alloc_aligned(size_t size, size_t align, int flags)
{ {
void *ptr; void *ptr = NULL;
int rc; int rc = EINVAL;
do { do {
rc = posix_memalign(&ptr, align, size); rc = posix_memalign(&ptr, align, size);
@ -117,7 +117,7 @@ umem_alloc_aligned(size_t size, size_t align, int flags)
static inline void * static inline void *
umem_zalloc(size_t size, int flags) umem_zalloc(size_t size, int flags)
{ {
void *ptr; void *ptr = NULL;
ptr = umem_alloc(size, flags); ptr = umem_alloc(size, flags);
if (ptr) if (ptr)
@ -170,7 +170,7 @@ umem_cache_destroy(umem_cache_t *cp)
static inline void * static inline void *
umem_cache_alloc(umem_cache_t *cp, int flags) umem_cache_alloc(umem_cache_t *cp, int flags)
{ {
void *ptr; void *ptr = NULL;
if (cp->cache_align != 0) if (cp->cache_align != 0)
ptr = umem_alloc_aligned( ptr = umem_alloc_aligned(