summaryrefslogtreecommitdiffstats
path: root/tools/h5toh4.c
diff options
context:
space:
mode:
authorPaul Harten <pharten@ncsa.uiuc.edu>1999-01-12 15:48:18 (GMT)
committerPaul Harten <pharten@ncsa.uiuc.edu>1999-01-12 15:48:18 (GMT)
commit2362b4e0f0dda6237c994551e01cdd2773bad019 (patch)
tree628b5ae14e2303cb3040c25adef4964e14296510 /tools/h5toh4.c
parent6c30f0ae168fa5e7cdfb1553ef41553b20350573 (diff)
downloadhdf5-2362b4e0f0dda6237c994551e01cdd2773bad019.zip
hdf5-2362b4e0f0dda6237c994551e01cdd2773bad019.tar.gz
hdf5-2362b4e0f0dda6237c994551e01cdd2773bad019.tar.bz2
[svn-r1021] Purpose:
Bug fix Problem: Segmentation fault when attempting to free NULL or uninitialized pointers. Problem noticed on Linux and HPUX10.20 platforms. Solution: Initialialize the pointer to NULL. Execute the "free" statement upon the condition that the pointer is not equal to NULL (i.e. after the allocation has taken place.) Platform tested: Linux, HPUX10.20, Solaris2.5
Diffstat (limited to 'tools/h5toh4.c')
-rw-r--r--tools/h5toh4.c46
1 files changed, 31 insertions, 15 deletions
diff --git a/tools/h5toh4.c b/tools/h5toh4.c
index 09f04a9..bdc3df2 100644
--- a/tools/h5toh4.c
+++ b/tools/h5toh4.c
@@ -71,8 +71,9 @@ int
main(int argc, char **argv)
{
char **fargv;
- char *h5_filename, *h4_filename;
- char *h4_extension = "hdf";
+ char *h5_filename=NULL;
+ char *h4_filename=NULL;
+ char *h4_extension = "hdf";
int status = 0;
int status2 = 0;
@@ -145,7 +146,9 @@ main(int argc, char **argv)
if ( status != 0 ) {
DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "main", __FILE__, __LINE__);
}
- HDfree(h4_filename);
+ if (h4_filename != NULL) {
+ HDfree(h4_filename);
+ }
break;
@@ -235,7 +238,9 @@ main(int argc, char **argv)
DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "main", __FILE__, __LINE__);
status2 = status;
}
- HDfree(h4_filename);
+ if (h4_filename != NULL) {
+ HDfree(h4_filename);
+ }
}
status = status2;
@@ -406,7 +411,6 @@ int h5toh4(h5_filename, h4_filename)
}
done:
-
free_table();
return status;
@@ -585,9 +589,9 @@ int32 h4_type;
int32 recsize;
int32 n_records, num_of_recs, record_pos;
intn nmembers;
-char *buffer; /* read/write buffer*/
+char *buffer=NULL; /* read/write buffer*/
char fieldname_list[4096] = "\0";
-char *fieldname;
+char *fieldname=NULL;
hid_t fieldtype;
int32 order;
off_t offset;
@@ -849,7 +853,9 @@ int32 order_array[512];
strcat(fieldname_list,", ");
}
- HDfree(fieldname);
+ if (fieldname != NULL) {
+ HDfree(fieldname);
+ }
}
if ((status = VSsetfields(vdata_id, fieldname_list)) != SUCCEED ) {
fprintf(stderr, "Error: Unable to set fieldname list %s\n", name);
@@ -926,7 +932,9 @@ int32 order_array[512];
DEBUG_PRINT("Error detected in %s() [%s line %d]\n", "convert_dataset", __FILE__, __LINE__);
}
- HDfree(buffer);
+ if (buffer != NULL) {
+ HDfree(buffer);
+ }
return status;
@@ -953,7 +961,7 @@ convert_attr (hid_t attr, char *attr_name, op_data_t *op_data)
{
hid_t attr_id, type, space, mem_type, class;
size_t typesize;
-char *attr_values;
+char *attr_values=NULL;
int32 status;
int32 h4_type;
int32 sds_id;
@@ -1071,7 +1079,9 @@ int32 n_values;
return status;
}
- HDfree(attr_values);
+ if (attr_values != NULL) {
+ HDfree(attr_values);
+ }
status = SUCCEED;
break;
@@ -1456,7 +1466,8 @@ convert_shared_dataset(hid_t did, int idx, op_data_t *op_data)
{
int status=SUCCEED;
int32 vgroup_id;
- char *dataset_name, *dataset_name2;
+ char *dataset_name=NULL;
+ char *dataset_name2=NULL;
int32 hfile_id;
int32 sd_id;
int32 sds_id;
@@ -1579,7 +1590,9 @@ convert_shared_dataset(hid_t did, int idx, op_data_t *op_data)
status = FAIL;
}
- HDfree (dataset_name);
+ if (dataset_name != NULL) {
+ HDfree (dataset_name);
+ }
return status;
@@ -1605,7 +1618,8 @@ convert_shared_group (hid_t group, int idx, op_data_t *op_data) {
int32 vgroup_ref;
int32 numtagref;
int32 status;
- char *group_name, *group_name2;
+ char *group_name=NULL;
+ char *group_name2=NULL;
char vgroup_name[VGNAMELENMAX];
hfile_id = op_data->hfile_id;
@@ -1658,7 +1672,9 @@ convert_shared_group (hid_t group, int idx, op_data_t *op_data) {
status = FAIL;
}
- HDfree(group_name);
+ if (group_name != NULL) {
+ HDfree(group_name);
+ }
return status;