diff options
author | Shehjar Tikoo <shehjart@gluster.com> | 2009-09-09 00:46:29 +0000 |
---|---|---|
committer | Anand V. Avati <avati@dev.gluster.com> | 2009-09-09 06:39:11 -0700 |
commit | 6858391d8909abeb2d396e806df49f6cd3253c20 (patch) | |
tree | febe635dccb500f58b889c0ebba19fc5b59ae8d0 /libglusterfsclient | |
parent | baa85e6b797dd3f3b70772a712599cc3ab8597b5 (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')
-rwxr-xr-x | libglusterfsclient/src/libglusterfsclient.c | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/libglusterfsclient/src/libglusterfsclient.c b/libglusterfsclient/src/libglusterfsclient.c index 76cfec48dc7..5dd7fbc8def 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; } |