Ma Shimiao
2014-02-17 10:07:06 UTC
Add ErrorCreate when memory is not enough and can not access plugin.
Make some cleanup.
Add optional_data free when free Disk Record.
Signed-off-by: Ma Shimiao <***@cn.fujitsu.com>
---
src/lsm_datatypes.cpp | 44 +++++++++++++++++++++++++++++++++++---------
1 file changed, 35 insertions(+), 9 deletions(-)
diff --git a/src/lsm_datatypes.cpp b/src/lsm_datatypes.cpp
index 7e6415d..54c1432 100644
--- a/src/lsm_datatypes.cpp
+++ b/src/lsm_datatypes.cpp
@@ -230,6 +230,7 @@ void freeConnection(lsmConnect *c)
}
free(c);
+ c = NULL;
}
}
@@ -294,6 +295,11 @@ int loadDriver(lsmConnect *c, const char *plugin_name, const char *password,
const char *plugin_dir = uds_path();
if (asprintf(&plugin_file, "%s/%s", plugin_dir, plugin_name) == -1) {
+ *e = lsmErrorCreate(LSM_ERR_NO_MEMORY,
+ LSM_ERR_DOMAIN_FRAME_WORK,
+ LSM_ERR_LEVEL_ERROR, "Not enough memory",
+ NULL, NULL, NULL, 0 );
+
return LSM_ERR_NO_MEMORY;
}
@@ -317,6 +323,11 @@ int loadDriver(lsmConnect *c, const char *plugin_name, const char *password,
rc = LSM_ERR_PLUGIN_DLOPEN;
}
} else {
+ *e = lsmErrorCreate(LSM_ERR_PLUGIN_PERMISSIONS,
+ LSM_ERR_DOMAIN_FRAME_WORK,
+ LSM_ERR_LEVEL_ERROR, "Unable to access plugin",
+ NULL, NULL, NULL, 0 );
+
rc = LSM_ERR_PLUGIN_PERMISSIONS;
}
@@ -395,6 +406,7 @@ int lsmErrorFree(lsmErrorPtr e)
e->magic = LSM_DEL_MAGIC(LSM_ERROR_MAGIC);
free(e);
+ e = NULL;
return LSM_ERR_OK;
}
@@ -629,6 +641,9 @@ void lsmInitiatorRecordFree(lsmInitiator *i)
if (i->id) {
free(i->id);
i->id = NULL;
+ }
+
+ if (i->name) {
free(i->name);
i->name = NULL;
}
@@ -794,9 +809,9 @@ lsmVolume *lsmVolumeRecordCopy(lsmVolume *vol)
{
lsmVolume *rc = NULL;
if( LSM_IS_VOL(vol) ) {
- rc = lsmVolumeRecordAlloc( vol->id, vol->name, vol->vpd83,
- vol->blockSize, vol->numberOfBlocks,
- vol->status, vol->system_id, vol->pool_id);
+ rc = lsmVolumeRecordAlloc(vol->id, vol->name, vol->vpd83,
+ vol->blockSize, vol->numberOfBlocks,
+ vol->status, vol->system_id, vol->pool_id);
}
return rc;
}
@@ -853,14 +868,25 @@ void lsmDiskRecordFree(lsmDisk *d)
if ( LSM_IS_DISK(d) ) {
d->magic = LSM_DEL_MAGIC(LSM_DISK_MAGIC);
- free(d->id);
- d->id = NULL;
+ if( d->id ) {
+ free(d->id);
+ d->id = NULL;
+ }
- free(d->name);
- d->name = NULL;
+ if( d->name ) {
+ free(d->name);
+ d->name = NULL;
+ }
+
+ if( d->system_id ) {
+ free(d->system_id);
+ d->system_id = NULL;
+ }
- free(d->system_id);
- d->system_id = NULL;
+ if (d->optional_data) {
+ lsmOptionalDataRecordFree(d->optional_data);
+ d->optional_data = NULL;
+ }
free(d);
}
Make some cleanup.
Add optional_data free when free Disk Record.
Signed-off-by: Ma Shimiao <***@cn.fujitsu.com>
---
src/lsm_datatypes.cpp | 44 +++++++++++++++++++++++++++++++++++---------
1 file changed, 35 insertions(+), 9 deletions(-)
diff --git a/src/lsm_datatypes.cpp b/src/lsm_datatypes.cpp
index 7e6415d..54c1432 100644
--- a/src/lsm_datatypes.cpp
+++ b/src/lsm_datatypes.cpp
@@ -230,6 +230,7 @@ void freeConnection(lsmConnect *c)
}
free(c);
+ c = NULL;
}
}
@@ -294,6 +295,11 @@ int loadDriver(lsmConnect *c, const char *plugin_name, const char *password,
const char *plugin_dir = uds_path();
if (asprintf(&plugin_file, "%s/%s", plugin_dir, plugin_name) == -1) {
+ *e = lsmErrorCreate(LSM_ERR_NO_MEMORY,
+ LSM_ERR_DOMAIN_FRAME_WORK,
+ LSM_ERR_LEVEL_ERROR, "Not enough memory",
+ NULL, NULL, NULL, 0 );
+
return LSM_ERR_NO_MEMORY;
}
@@ -317,6 +323,11 @@ int loadDriver(lsmConnect *c, const char *plugin_name, const char *password,
rc = LSM_ERR_PLUGIN_DLOPEN;
}
} else {
+ *e = lsmErrorCreate(LSM_ERR_PLUGIN_PERMISSIONS,
+ LSM_ERR_DOMAIN_FRAME_WORK,
+ LSM_ERR_LEVEL_ERROR, "Unable to access plugin",
+ NULL, NULL, NULL, 0 );
+
rc = LSM_ERR_PLUGIN_PERMISSIONS;
}
@@ -395,6 +406,7 @@ int lsmErrorFree(lsmErrorPtr e)
e->magic = LSM_DEL_MAGIC(LSM_ERROR_MAGIC);
free(e);
+ e = NULL;
return LSM_ERR_OK;
}
@@ -629,6 +641,9 @@ void lsmInitiatorRecordFree(lsmInitiator *i)
if (i->id) {
free(i->id);
i->id = NULL;
+ }
+
+ if (i->name) {
free(i->name);
i->name = NULL;
}
@@ -794,9 +809,9 @@ lsmVolume *lsmVolumeRecordCopy(lsmVolume *vol)
{
lsmVolume *rc = NULL;
if( LSM_IS_VOL(vol) ) {
- rc = lsmVolumeRecordAlloc( vol->id, vol->name, vol->vpd83,
- vol->blockSize, vol->numberOfBlocks,
- vol->status, vol->system_id, vol->pool_id);
+ rc = lsmVolumeRecordAlloc(vol->id, vol->name, vol->vpd83,
+ vol->blockSize, vol->numberOfBlocks,
+ vol->status, vol->system_id, vol->pool_id);
}
return rc;
}
@@ -853,14 +868,25 @@ void lsmDiskRecordFree(lsmDisk *d)
if ( LSM_IS_DISK(d) ) {
d->magic = LSM_DEL_MAGIC(LSM_DISK_MAGIC);
- free(d->id);
- d->id = NULL;
+ if( d->id ) {
+ free(d->id);
+ d->id = NULL;
+ }
- free(d->name);
- d->name = NULL;
+ if( d->name ) {
+ free(d->name);
+ d->name = NULL;
+ }
+
+ if( d->system_id ) {
+ free(d->system_id);
+ d->system_id = NULL;
+ }
- free(d->system_id);
- d->system_id = NULL;
+ if (d->optional_data) {
+ lsmOptionalDataRecordFree(d->optional_data);
+ d->optional_data = NULL;
+ }
free(d);
}
--
1.8.3.1
1.8.3.1