Tony Asleson
2015-04-29 15:12:46 UTC
Not always consistent checking the return for NULL.
Signed-off-by: Tony Asleson <***@redhat.com>
---
c_binding/lsm_convert.cpp | 21 +++++++++++----
c_binding/lsm_mgmt.cpp | 54 ++++++++++++++++++++++++++++++++---------
c_binding/lsm_plugin_ipc.cpp | 3 +-
3 files changed, 59 insertions(+), 19 deletions(-)
diff --git a/c_binding/lsm_convert.cpp b/c_binding/lsm_convert.cpp
index d7c31fa..8cde280 100644
--- a/c_binding/lsm_convert.cpp
+++ b/c_binding/lsm_convert.cpp
@@ -92,6 +92,10 @@ int value_array_to_volumes(Value &volume_values, lsm_volume **volumes[],
if( *volumes ){
for( size_t i = 0; i < vol.size(); ++i ) {
(*volumes)[i] = value_to_volume(vol[i]);
+ if( !((*volumes)[i]) ) {
+ rc = LSM_ERR_NO_MEMORY;
+ goto error;
+ }
}
} else {
rc = LSM_ERR_NO_MEMORY;
@@ -99,15 +103,20 @@ int value_array_to_volumes(Value &volume_values, lsm_volume **volumes[],
}
}
} catch( const ValueException &ve) {
- if( *volumes && *count ) {
- lsm_volume_record_array_free(*volumes, *count);
- *volumes = NULL;
- *count = 0;
- }
-
rc = LSM_ERR_LIB_BUG;
+ goto error;
}
+
+out:
return rc;
+
+error:
+ if( *volumes && *count ) {
+ lsm_volume_record_array_free(*volumes, *count);
+ *volumes = NULL;
+ *count = 0;
+ }
+ goto out;
}
lsm_disk *value_to_disk(Value &disk)
diff --git a/c_binding/lsm_mgmt.cpp b/c_binding/lsm_mgmt.cpp
index cbe57fe..5075f74 100644
--- a/c_binding/lsm_mgmt.cpp
+++ b/c_binding/lsm_mgmt.cpp
@@ -627,6 +627,9 @@ int lsm_job_status_volume_get( lsm_connect *c, const char *job,
if( LSM_ERR_OK == rc ) {
if( Value::object_t == rv.valueType() ) {
*vol = value_to_volume(rv);
+ if( !(*vol) ) {
+ rc = LSM_ERR_NO_MEMORY;
+ }
} else {
*vol = NULL;
}
@@ -1001,6 +1004,7 @@ static void* parse_job_response(lsm_connect *c, Value response, int &rc,
char **job, convert conv)
{
void *val = NULL;
+ *job = NULL;
try {
//We get an array back. first value is job, second is data of interest.
@@ -1008,25 +1012,34 @@ static void* parse_job_response(lsm_connect *c, Value response, int &rc,
std::vector<Value> r = response.asArray();
if( Value::string_t == r[0].valueType()) {
*job = strdup((r[0].asString()).c_str());
- if( *job ) {
- rc = LSM_ERR_JOB_STARTED;
- } else {
+ if( !(*job) ) {
rc = LSM_ERR_NO_MEMORY;
+ goto error;
}
rc = LSM_ERR_JOB_STARTED;
}
if( Value::object_t == r[1].valueType() ) {
val = conv(r[1]);
+ if( !val ) {
+ rc = LSM_ERR_NO_MEMORY;
+ goto error;
+ }
}
}
} catch( const ValueException &ve ) {
rc = logException(c, LSM_ERR_LIB_BUG, "Unexpected type",
ve.what());
- free(*job);
- *job = NULL;
+ goto error;
}
+
+out:
return val;
+
+error:
+ free(*job);
+ *job = NULL;
+ goto out;
}
int lsm_volume_create(lsm_connect *c, lsm_pool *pool, const char *volumeName,
@@ -1560,21 +1573,35 @@ int lsm_volumes_accessible_by_access_group(lsm_connect *c,
if( vol.size() ) {
*volumes = lsm_volume_record_array_alloc(vol.size());
- for( size_t i = 0; i < vol.size(); ++i ) {
- (*volumes)[i] = value_to_volume(vol[i]);
+ if( *volumes ) {
+ for( size_t i = 0; i < vol.size(); ++i ) {
+ (*volumes)[i] = value_to_volume(vol[i]);
+ if( !((*volumes)[i]) ) {
+ rc = LSM_ERR_NO_MEMORY;
+ goto error;
+ }
+ }
+ } else {
+ rc = LSM_ERR_NO_MEMORY;
}
}
}
} catch( const ValueException &ve ) {
rc = logException(c, LSM_ERR_LIB_BUG, "Unexpected type",
ve.what());
- if( *volumes && *count ) {
- lsm_volume_record_array_free(*volumes, *count);
- *volumes = NULL;
- *count = 0;
- }
+ goto error;
+
}
+
+out:
return rc;
+
+error:
+ if( *volumes && *count ) {
+ lsm_volume_record_array_free(*volumes, *count);
+ *volumes = NULL;
+ *count = 0;
+ }
}
int lsm_access_groups_granted_to_volume(lsm_connect *c,
@@ -2393,6 +2420,9 @@ int lsm_volume_raid_create(
int rc = rpc(c, "volume_raid_create", parameters, response);
if( LSM_ERR_OK == rc ) {
*new_volume = value_to_volume(response);
+ if( ! (*new_volume) ) {
+ rc = LSM_ERR_NO_MEMORY;
+ }
}
return rc;
diff --git a/c_binding/lsm_plugin_ipc.cpp b/c_binding/lsm_plugin_ipc.cpp
index d1b2b41..667b95f 100644
--- a/c_binding/lsm_plugin_ipc.cpp
+++ b/c_binding/lsm_plugin_ipc.cpp
@@ -791,7 +791,8 @@ static int handle_volume_replicate(lsm_plugin_ptr p, Value ¶ms, Value &respo
const char *name = v_name.asC_str();
char *job = NULL;
- if( vol ) {
+ if( vol && (pool ||
+ (!pool && Value::null_t == v_pool.valueType())) ) {
rc = p->san_ops->vol_replicate(p, pool, rep, vol, name,
&newVolume, &job,
LSM_FLAG_GET_VALUE(params));
Signed-off-by: Tony Asleson <***@redhat.com>
---
c_binding/lsm_convert.cpp | 21 +++++++++++----
c_binding/lsm_mgmt.cpp | 54 ++++++++++++++++++++++++++++++++---------
c_binding/lsm_plugin_ipc.cpp | 3 +-
3 files changed, 59 insertions(+), 19 deletions(-)
diff --git a/c_binding/lsm_convert.cpp b/c_binding/lsm_convert.cpp
index d7c31fa..8cde280 100644
--- a/c_binding/lsm_convert.cpp
+++ b/c_binding/lsm_convert.cpp
@@ -92,6 +92,10 @@ int value_array_to_volumes(Value &volume_values, lsm_volume **volumes[],
if( *volumes ){
for( size_t i = 0; i < vol.size(); ++i ) {
(*volumes)[i] = value_to_volume(vol[i]);
+ if( !((*volumes)[i]) ) {
+ rc = LSM_ERR_NO_MEMORY;
+ goto error;
+ }
}
} else {
rc = LSM_ERR_NO_MEMORY;
@@ -99,15 +103,20 @@ int value_array_to_volumes(Value &volume_values, lsm_volume **volumes[],
}
}
} catch( const ValueException &ve) {
- if( *volumes && *count ) {
- lsm_volume_record_array_free(*volumes, *count);
- *volumes = NULL;
- *count = 0;
- }
-
rc = LSM_ERR_LIB_BUG;
+ goto error;
}
+
+out:
return rc;
+
+error:
+ if( *volumes && *count ) {
+ lsm_volume_record_array_free(*volumes, *count);
+ *volumes = NULL;
+ *count = 0;
+ }
+ goto out;
}
lsm_disk *value_to_disk(Value &disk)
diff --git a/c_binding/lsm_mgmt.cpp b/c_binding/lsm_mgmt.cpp
index cbe57fe..5075f74 100644
--- a/c_binding/lsm_mgmt.cpp
+++ b/c_binding/lsm_mgmt.cpp
@@ -627,6 +627,9 @@ int lsm_job_status_volume_get( lsm_connect *c, const char *job,
if( LSM_ERR_OK == rc ) {
if( Value::object_t == rv.valueType() ) {
*vol = value_to_volume(rv);
+ if( !(*vol) ) {
+ rc = LSM_ERR_NO_MEMORY;
+ }
} else {
*vol = NULL;
}
@@ -1001,6 +1004,7 @@ static void* parse_job_response(lsm_connect *c, Value response, int &rc,
char **job, convert conv)
{
void *val = NULL;
+ *job = NULL;
try {
//We get an array back. first value is job, second is data of interest.
@@ -1008,25 +1012,34 @@ static void* parse_job_response(lsm_connect *c, Value response, int &rc,
std::vector<Value> r = response.asArray();
if( Value::string_t == r[0].valueType()) {
*job = strdup((r[0].asString()).c_str());
- if( *job ) {
- rc = LSM_ERR_JOB_STARTED;
- } else {
+ if( !(*job) ) {
rc = LSM_ERR_NO_MEMORY;
+ goto error;
}
rc = LSM_ERR_JOB_STARTED;
}
if( Value::object_t == r[1].valueType() ) {
val = conv(r[1]);
+ if( !val ) {
+ rc = LSM_ERR_NO_MEMORY;
+ goto error;
+ }
}
}
} catch( const ValueException &ve ) {
rc = logException(c, LSM_ERR_LIB_BUG, "Unexpected type",
ve.what());
- free(*job);
- *job = NULL;
+ goto error;
}
+
+out:
return val;
+
+error:
+ free(*job);
+ *job = NULL;
+ goto out;
}
int lsm_volume_create(lsm_connect *c, lsm_pool *pool, const char *volumeName,
@@ -1560,21 +1573,35 @@ int lsm_volumes_accessible_by_access_group(lsm_connect *c,
if( vol.size() ) {
*volumes = lsm_volume_record_array_alloc(vol.size());
- for( size_t i = 0; i < vol.size(); ++i ) {
- (*volumes)[i] = value_to_volume(vol[i]);
+ if( *volumes ) {
+ for( size_t i = 0; i < vol.size(); ++i ) {
+ (*volumes)[i] = value_to_volume(vol[i]);
+ if( !((*volumes)[i]) ) {
+ rc = LSM_ERR_NO_MEMORY;
+ goto error;
+ }
+ }
+ } else {
+ rc = LSM_ERR_NO_MEMORY;
}
}
}
} catch( const ValueException &ve ) {
rc = logException(c, LSM_ERR_LIB_BUG, "Unexpected type",
ve.what());
- if( *volumes && *count ) {
- lsm_volume_record_array_free(*volumes, *count);
- *volumes = NULL;
- *count = 0;
- }
+ goto error;
+
}
+
+out:
return rc;
+
+error:
+ if( *volumes && *count ) {
+ lsm_volume_record_array_free(*volumes, *count);
+ *volumes = NULL;
+ *count = 0;
+ }
}
int lsm_access_groups_granted_to_volume(lsm_connect *c,
@@ -2393,6 +2420,9 @@ int lsm_volume_raid_create(
int rc = rpc(c, "volume_raid_create", parameters, response);
if( LSM_ERR_OK == rc ) {
*new_volume = value_to_volume(response);
+ if( ! (*new_volume) ) {
+ rc = LSM_ERR_NO_MEMORY;
+ }
}
return rc;
diff --git a/c_binding/lsm_plugin_ipc.cpp b/c_binding/lsm_plugin_ipc.cpp
index d1b2b41..667b95f 100644
--- a/c_binding/lsm_plugin_ipc.cpp
+++ b/c_binding/lsm_plugin_ipc.cpp
@@ -791,7 +791,8 @@ static int handle_volume_replicate(lsm_plugin_ptr p, Value ¶ms, Value &respo
const char *name = v_name.asC_str();
char *job = NULL;
- if( vol ) {
+ if( vol && (pool ||
+ (!pool && Value::null_t == v_pool.valueType())) ) {
rc = p->san_ops->vol_replicate(p, pool, rep, vol, name,
&newVolume, &job,
LSM_FLAG_GET_VALUE(params));
--
1.7.1
1.7.1