summaryrefslogtreecommitdiffstats
path: root/libglusterfsclient/src
diff options
context:
space:
mode:
authorShehjar Tikoo <shehjart@gluster.com>2009-09-09 00:39:10 +0000
committerAnand V. Avati <avati@dev.gluster.com>2009-09-09 06:38:46 -0700
commitbc94b7e77fffcbcde8f838cae8fee552d5bd1189 (patch)
tree74475fd166ed671369cf71f9f9820a2da215f029 /libglusterfsclient/src
parent226c228ff8effd6cc5edcb3326907b1faf69eaea (diff)
libglusterfsclient: Handle CALLOC failure in libgf_init_vmpentry
Signed-off-by: Anand V. Avati <avati@dev.gluster.com> BUG: 253 (Global bug for libglusterfsclient NULL checks and CALLOC handling fixes) URL: http://bugs.gluster.com/cgi-bin/bugzilla3/show_bug.cgi?id=253
Diffstat (limited to 'libglusterfsclient/src')
-rwxr-xr-xlibglusterfsclient/src/libglusterfsclient.c18
1 files changed, 18 insertions, 0 deletions
diff --git a/libglusterfsclient/src/libglusterfsclient.c b/libglusterfsclient/src/libglusterfsclient.c
index 8f7ae8809..6860e1e36 100755
--- a/libglusterfsclient/src/libglusterfsclient.c
+++ b/libglusterfsclient/src/libglusterfsclient.c
@@ -1357,6 +1357,7 @@ libgf_init_vmpentry (char *vmp, glusterfs_handle_t *vmphandle)
struct vmp_entry *entry = NULL;
int vmplen = 0;
int appendslash = 0;
+ int ret = -1;
entry = CALLOC (1, sizeof (struct vmp_entry));
if (!entry) {
@@ -1371,6 +1372,12 @@ libgf_init_vmpentry (char *vmp, glusterfs_handle_t *vmphandle)
}
entry->vmp = CALLOC (vmplen, sizeof (char));
+ if (!entry->vmp) {
+ gf_log (LIBGF_XL_NAME, GF_LOG_ERROR, "Memory allocation "
+ "failed");
+ goto free_entry;
+ }
+
strcpy (entry->vmp, vmp);
if (appendslash)
entry->vmp[vmplen-1] = '/';
@@ -1378,6 +1385,17 @@ libgf_init_vmpentry (char *vmp, glusterfs_handle_t *vmphandle)
entry->handle = vmphandle;
INIT_LIST_HEAD (&entry->list);
gf_log (LIBGF_XL_NAME, GF_LOG_DEBUG, "New VMP entry: %s", vmp);
+
+ ret = 0;
+
+free_entry:
+ if (ret == -1) {
+ if (entry->vmp)
+ FREE (entry->vmp);
+ if (entry)
+ FREE (entry);
+ entry = NULL;
+ }
return entry;
}