1
0
mirror of https://github.com/TREX-CoE/trexio.git synced 2024-11-03 20:54:07 +01:00

fix leaking memory

This commit is contained in:
q-posev 2021-03-04 18:53:13 +01:00
parent e52cfbafea
commit db1f1d6980
3 changed files with 14 additions and 16 deletions

View File

@ -74,7 +74,11 @@ trexio_t* trexio_open(const char* file_name, const char mode, const back_end_t b
break;
*/
}
if (rc != TREXIO_SUCCESS) return NULL;
if (rc != TREXIO_SUCCESS) {
free(result->file_name);
free(result);
return NULL;
}
return result;
}

View File

@ -94,9 +94,9 @@ trexio_exit_code trexio_hdf5_init(trexio_t* file) {
switch (file->mode) {
case 'r':
case 'a':
// reading non-existing file -> error
return TREXIO_FAILURE;
case 'a':
case 'w':
// appending or writing non-existing file -> create it
f->file_id = H5Fcreate(file->file_name, H5F_ACC_EXCL, H5P_DEFAULT, H5P_DEFAULT);
@ -109,13 +109,8 @@ trexio_exit_code trexio_hdf5_init(trexio_t* file) {
switch (file->mode) {
case 'r':
case 'a':
if (f_exists == 1) {
f->nucleus_group = H5Gopen(f->file_id, NUCLEUS_GROUP_NAME, H5P_DEFAULT);
//f->electron_group = H5Gopen(f->file_id, ELECTRON_GROUP_NAME, H5P_DEFAULT);
} else {
f->nucleus_group = H5Gcreate(f->file_id, NUCLEUS_GROUP_NAME, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
//f->electron_group = H5Gcreate(f->file_id, ELECTRON_GROUP_NAME, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
}
break;
case 'w':
f->nucleus_group = H5Gcreate(f->file_id, NUCLEUS_GROUP_NAME, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
@ -442,6 +437,8 @@ trexio_exit_code trexio_hdf5_read_nucleus_coord(const trexio_t* file, double* co
assert (status >= 0);
free(ddims);
return TREXIO_SUCCESS;
}

View File

@ -185,9 +185,9 @@ trexio_exit_code trexio_hdf5_init(trexio_t* file) {
switch (file->mode) {
case 'r':
case 'a':
// reading non-existing file -> error
return TREXIO_FAILURE;
case 'a':
case 'w':
// appending or writing non-existing file -> create it
f->file_id = H5Fcreate(file->file_name, H5F_ACC_EXCL, H5P_DEFAULT, H5P_DEFAULT);
@ -200,13 +200,8 @@ trexio_exit_code trexio_hdf5_init(trexio_t* file) {
switch (file->mode) {
case 'r':
case 'a':
if (f_exists == 1) {
f->nucleus_group = H5Gopen(f->file_id, NUCLEUS_GROUP_NAME, H5P_DEFAULT);
//f->electron_group = H5Gopen(f->file_id, ELECTRON_GROUP_NAME, H5P_DEFAULT);
} else {
f->nucleus_group = H5Gcreate(f->file_id, NUCLEUS_GROUP_NAME, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
//f->electron_group = H5Gcreate(f->file_id, ELECTRON_GROUP_NAME, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
}
break;
case 'w':
f->nucleus_group = H5Gcreate(f->file_id, NUCLEUS_GROUP_NAME, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
@ -605,6 +600,8 @@ trexio_exit_code trexio_hdf5_read_nucleus_coord(const trexio_t* file, double* co
assert (status >= 0);
free(ddims);
return TREXIO_SUCCESS;
}