summaryrefslogtreecommitdiffstats
path: root/libglusterfs/src/mem-pool.c
diff options
context:
space:
mode:
authorAmar Tumballi <amar@gluster.com>2011-03-16 09:38:21 +0000
committerVijay Bellur <vijay@dev.gluster.com>2011-03-17 11:57:11 -0700
commitebe47d5dae42da18b289e7be44eb67a8157a56b1 (patch)
tree13d3c68f86ca5dec97f8a1ca183d801bc9d3c92b /libglusterfs/src/mem-pool.c
parentce01662eefb575d1afe397486653920ec101f40f (diff)
libglusterfs: gf_log_nomem() and other minor updates
log will be done when the memory allocation fails, hence in code, no explicit logs required for memory allocation failures. also, if there are logs before actually doing a log_init(), they will be logged in 'stderr'. Signed-off-by: Amar Tumballi <amar@gluster.com> Signed-off-by: Vijay Bellur <vijay@dev.gluster.com> BUG: 2346 (Log message enhancements in GlusterFS - phase 1) URL: http://bugs.gluster.com/cgi-bin/bugzilla3/show_bug.cgi?id=2346
Diffstat (limited to 'libglusterfs/src/mem-pool.c')
-rw-r--r--libglusterfs/src/mem-pool.c23
1 files changed, 11 insertions, 12 deletions
diff --git a/libglusterfs/src/mem-pool.c b/libglusterfs/src/mem-pool.c
index 9acebad4153..0d555020bbe 100644
--- a/libglusterfs/src/mem-pool.c
+++ b/libglusterfs/src/mem-pool.c
@@ -141,9 +141,10 @@ __gf_calloc (size_t nmemb, size_t size, uint32_t type)
ptr = calloc (1, tot_size);
- if (!ptr)
+ if (!ptr) {
+ gf_log_nomem ("", GF_LOG_ALERT, tot_size);
return NULL;
-
+ }
gf_mem_set_acct_info (xl, &ptr, req_size, type);
return (void *)ptr;
@@ -164,9 +165,10 @@ __gf_malloc (size_t size, uint32_t type)
tot_size = size + GF_MEM_HEADER_SIZE + GF_MEM_TRAILER_SIZE;
ptr = malloc (tot_size);
- if (!ptr)
+ if (!ptr) {
+ gf_log_nomem ("", GF_LOG_ALERT, tot_size);
return NULL;
-
+ }
gf_mem_set_acct_info (xl, &ptr, size, type);
return (void *)ptr;
@@ -181,7 +183,7 @@ __gf_realloc (void *ptr, size_t size)
uint32_t type = 0;
if (!gf_mem_acct_enable)
- return realloc (ptr, size);
+ return REALLOC (ptr, size);
tot_size = size + GF_MEM_HEADER_SIZE + GF_MEM_TRAILER_SIZE;
@@ -196,8 +198,10 @@ __gf_realloc (void *ptr, size_t size)
type = *(uint32_t *)orig_ptr;
ptr = realloc (orig_ptr, tot_size);
- if (!ptr)
+ if (!ptr) {
+ gf_log_nomem ("", GF_LOG_ALERT, tot_size);
return NULL;
+ }
gf_mem_set_acct_info (xl, (char **)&ptr, size, type);
@@ -221,12 +225,7 @@ gf_vasprintf (char **string_ptr, const char *format, va_list arg)
size++;
str = GF_MALLOC (size, gf_common_mt_asprintf);
if (str == NULL) {
- /*
- * Strictly speaking, GNU asprintf doesn't do this,
- * but the caller isn't checking the return value.
- */
- gf_log ("libglusterfs", GF_LOG_CRITICAL,
- "failed to allocate memory");
+ /* log is done in GF_MALLOC itself */
return -1;
}
rv = vsnprintf (str, size, format, arg_save);