1
0
mirror of https://github.com/TREX-CoE/trexio.git synced 2024-12-22 12:23:54 +01:00

fix memory leak in the Fortran test

This commit is contained in:
q-posev 2021-12-13 09:59:27 +01:00
parent 070ef06818
commit b90abcc307
2 changed files with 38 additions and 36 deletions

View File

@ -880,42 +880,6 @@ trexio_open(const char* file_name, const char mode,
return NULL;
}
rc = trexio_has_metadata_package_version(result);
if (rc == TREXIO_FAILURE) {
if (rc_open != NULL) *rc_open = TREXIO_OPEN_ERROR;
free(result);
return NULL;
}
if (rc == TREXIO_HAS_NOT) {
switch (back_end) {
case TREXIO_TEXT:
rc = trexio_text_write_metadata_package_version(result, TREXIO_PACKAGE_VERSION);
break;
case TREXIO_HDF5:
#ifdef HAVE_HDF5
rc = trexio_hdf5_write_metadata_package_version(result, TREXIO_PACKAGE_VERSION);
break;
#else
if (rc_open != NULL) *rc_open = TREXIO_BACK_END_MISSING;
return NULL;
#endif
/*
case TREXIO_JSON:
rc = trexio_json_write_metadata_package_version(result, TREXIO_PACKAGE_VERSION);
break;
,*/
}
}
if (rc != TREXIO_SUCCESS) {
if (rc_open != NULL) *rc_open = TREXIO_OPEN_ERROR;
free(result);
return NULL;
}
/* File locking */
@ -948,7 +912,42 @@ trexio_open(const char* file_name, const char mode,
return NULL;
}
/* Write metadata (i.e. package version) upon creation */
rc = trexio_has_metadata_package_version(result);
if (rc == TREXIO_FAILURE) {
if (rc_open != NULL) *rc_open = TREXIO_OPEN_ERROR;
free(result);
return NULL;
}
if (rc == TREXIO_HAS_NOT) {
switch (back_end) {
case TREXIO_TEXT:
rc = trexio_text_write_metadata_package_version(result, TREXIO_PACKAGE_VERSION);
break;
case TREXIO_HDF5:
#ifdef HAVE_HDF5
rc = trexio_hdf5_write_metadata_package_version(result, TREXIO_PACKAGE_VERSION);
break;
#else
if (rc_open != NULL) *rc_open = TREXIO_BACK_END_MISSING;
return NULL;
#endif
}
}
if (rc != TREXIO_SUCCESS) {
if (rc_open != NULL) *rc_open = TREXIO_OPEN_ERROR;
free(result);
return NULL;
}
/* Exit upon success */
if (rc_open != NULL) *rc_open = TREXIO_SUCCESS;
return result;
}
#+end_src

View File

@ -338,6 +338,9 @@ subroutine test_read_void(file_name, back_end)
! ================= START OF TEST ===================== !
trex_file = trexio_open(file_name, 'r', back_end, rc)
if (rc /= TREXIO_OPEN_ERROR) then
rc = trexio_close(trex_file)
endif
call trexio_assert(rc, TREXIO_OPEN_ERROR)
call trexio_string_of_error(rc, str)