summaryrefslogtreecommitdiffstats
path: root/libglusterfs
diff options
context:
space:
mode:
authorCsaba Henk <csaba@gluster.com>2010-03-24 14:01:36 +0000
committerAnand V. Avati <avati@dev.gluster.com>2010-03-31 09:43:29 -0700
commit41f05fcefc1c192a3f322e827114897ec0ace316 (patch)
treec5500aed5d5f993256a98341b2482fdefaf3c3c1 /libglusterfs
parentaa6028a600ccfea14d3f047402dfe157047cabdc (diff)
Fix further cppcheck reported issues.
Reported-by: Patrick Matthäi <pmatthaei@debian.org> Signed-off-by: Csaba Henk <csaba@gluster.com> Signed-off-by: Anand V. Avati <avati@dev.gluster.com> BUG: 420 (fix leaks pointed out by cppcheck static analyzer) URL: http://bugs.gluster.com/cgi-bin/bugzilla3/show_bug.cgi?id=420
Diffstat (limited to 'libglusterfs')
-rw-r--r--libglusterfs/src/dict.c27
-rw-r--r--libglusterfs/src/fd.c3
-rw-r--r--libglusterfs/src/spec.y21
3 files changed, 43 insertions, 8 deletions
diff --git a/libglusterfs/src/dict.c b/libglusterfs/src/dict.c
index b8728ac13..9e97bf1d4 100644
--- a/libglusterfs/src/dict.c
+++ b/libglusterfs/src/dict.c
@@ -168,19 +168,32 @@ data_copy (data_t *old)
if (old) {
newdata->len = old->len;
- if (old->data)
+ if (old->data) {
newdata->data = memdup (old->data, old->len);
- if (old->vec)
+ if (!newdata->data)
+ goto err_out;
+ }
+ if (old->vec) {
newdata->vec = memdup (old->vec, old->len * (sizeof (void *) +
sizeof (size_t)));
- if (!old->data && !old->vec) {
- gf_log ("dict", GF_LOG_CRITICAL,
- "@newdata->data || @newdata->vec got NULL from CALLOC()");
- return NULL;
+ if (!newdata->vec)
+ goto err_out;
}
}
return newdata;
+
+ err_out:
+
+ if (newdata->data)
+ FREE (newdata->data);
+ if (newdata->vec)
+ FREE (newdata->vec);
+ FREE (newdata);
+
+ gf_log ("dict", GF_LOG_CRITICAL,
+ "@newdata->data || @newdata->vec got NULL from CALLOC()");
+ return NULL;
}
static data_pair_t *
@@ -248,6 +261,8 @@ _dict_set (dict_t *this,
if (!pair->key) {
gf_log ("dict", GF_LOG_CRITICAL,
"@pair->key - NULL returned by CALLOC");
+ FREE (pair);
+
return -1;
}
diff --git a/libglusterfs/src/fd.c b/libglusterfs/src/fd.c
index b24d0089d..ee529f356 100644
--- a/libglusterfs/src/fd.c
+++ b/libglusterfs/src/fd.c
@@ -461,12 +461,13 @@ fd_unref (fd_t *fd)
fd_t *
fd_bind (fd_t *fd)
{
- inode_t *inode = fd->inode;
+ inode_t *inode = NULL;
if (!fd) {
gf_log ("fd.c", GF_LOG_ERROR, "fd is NULL");
return NULL;
}
+ inode = fd->inode;
LOCK (&inode->lock);
{
diff --git a/libglusterfs/src/spec.y b/libglusterfs/src/spec.y
index ec9101a2c..84ab4df85 100644
--- a/libglusterfs/src/spec.y
+++ b/libglusterfs/src/spec.y
@@ -152,11 +152,18 @@ new_section (char *name)
{
extern int yylineno;
xlator_t *trav = complete_tree;
- xlator_t *node = (void *) calloc (1, sizeof (*node));
+ xlator_t *node = NULL;
+
+ node = (void *) calloc (1, sizeof (*node));
+ if (!node) {
+ gf_log ("parser", GF_LOG_ERROR, "Out of memory");
+ return -1;
+ }
if (!name) {
gf_log ("parser", GF_LOG_DEBUG,
"Invalid argument name: '%s'", name);
+ FREE (node);
return -1;
}
@@ -283,6 +290,10 @@ section_sub (char *sub)
}
xlparent = (void *) calloc (1, sizeof (*xlparent));
+ if (!xlparent) {
+ gf_log ("parser", GF_LOG_ERROR, "Out of memory");
+ return -1;
+ }
xlparent->xlator = tree;
tmp = trav->parents;
@@ -295,6 +306,11 @@ section_sub (char *sub)
}
xlchild = (void *) calloc (1, sizeof(*xlchild));
+ if (!xlchild) {
+ FREE (xlparent);
+ gf_log ("parser", GF_LOG_ERROR, "Out of memory");
+ return -1;
+ }
xlchild->xlator = trav;
tmp = tree->children;
@@ -476,11 +492,14 @@ parse_backtick (FILE *srcfp, FILE *dstfp)
cmd = CALLOC (cmd_buf_size, 1);
if (cmd == NULL) {
+ gf_log ("parser", GF_LOG_ERROR, "Out of memory");
return -1;
}
result = CALLOC (cmd_buf_size * 2, 1);
if (result == NULL) {
+ FREE (cmd);
+ gf_log ("parser", GF_LOG_ERROR, "Out of memory");
return -1;
}