int lib_free_env(void) { LIBENV *env = lib_get_ptr(); LIBMEM *desc; /* check if the library environment is inactive */ if (env == NULL) return 1; #if 1 /* close streams which are still open */ while (env->file_ptr != NULL) xfclose(env->file_ptr); #endif /* free memory blocks which are still allocated */ while (env->mem_ptr != NULL) { desc = env->mem_ptr; env->mem_ptr = desc->next; free(desc); } #if 0 /* close streams which are still open */ for (k = 0; k < LIB_MAX_OPEN; k++) if (env->file_slot[k] != NULL) fclose(env->file_slot[k]); #endif #if 1 if (env->h_odbc != NULL) xdlclose(env->h_odbc); if (env->h_mysql != NULL) xdlclose(env->h_mysql); #endif /* free memory allocated to the environment block */ free(env); /* reset a pointer to the environment block */ lib_set_ptr(NULL); /* deinitialization successful */ return 0; }
int glp_free_env(void) { ENV *env = tls_get_ptr(); MBD *desc; /* check if the environment is active */ if (env == NULL) return 1; /* check if the environment block is valid */ if (env->self != env) { fprintf(stderr, "Invalid GLPK environment\n"); fflush(stderr); abort(); } /* close handles to shared libraries */ if (env->h_odbc != NULL) xdlclose(env->h_odbc); if (env->h_mysql != NULL) xdlclose(env->h_mysql); /* free memory blocks which are still allocated */ while (env->mem_ptr != NULL) { desc = env->mem_ptr; env->mem_ptr = desc->next; free(desc); } /* close text file used for copying terminal output */ if (env->tee_file != NULL) fclose(env->tee_file); /* invalidate the environment block */ env->self = NULL; /* free memory allocated to the environment block */ free(env->term_buf); free(env->err_buf); free(env); /* reset a pointer to the environment block */ tls_set_ptr(NULL); /* termination successful */ return 0; }
int glp_free_env(void) { ENV *env = tls_get_ptr(); MEM *desc; /* check if the environment is active */ if (env == NULL) return 1; /* check if the environment block is valid */ if (env->magic != ENV_MAGIC) { fprintf(stderr, "Invalid GLPK environment\n"); fflush(stderr); abort(); } /* close handles to shared libraries */ if (env->h_odbc != NULL) xdlclose(env->h_odbc); if (env->h_mysql != NULL) xdlclose(env->h_mysql); /* close streams which are still open */ while (env->file_ptr != NULL) xfclose(env->file_ptr); /* free memory blocks which are still allocated */ while (env->mem_ptr != NULL) { desc = env->mem_ptr; env->mem_ptr = desc->next; free(desc); } /* invalidate the environment block */ env->magic = -1; /* free memory allocated to the environment block */ free(env->term_buf); free(env->ioerr_msg); free(env); /* reset a pointer to the environment block */ tls_set_ptr(NULL); /* termination successful */ return 0; }