/** * @brief Free a not more useful mps_context. * * @param s the mps_context struct pointer to free. */ void mps_context_free (mps_context * s) { if (s->initialized) mps_free_data (s); free (s->input_config); free (s->output_config); /* Check if secular equation or monomial poly need to be freed */ if (s->active_poly != NULL) mps_polynomial_free (s, s->active_poly); s->active_poly = NULL; if (s->secular_equation) mps_secular_equation_free (s, MPS_POLYNOMIAL (s->secular_equation)); /* Close input and output streams if they're not stdin, stdout and * stderr */ if (s->instr != stdin && s->instr != NULL) fclose (s->instr); if (s->logstr != stderr && s->logstr != stdout && s->logstr != NULL) fclose (s->logstr); free (s); }
/** * @brief Free a not more useful mps_context. * * @param s the mps_context struct pointer to free. */ void mps_context_free (mps_context * s) { /* Close input and output streams if they're not stdin, stdout and * stderr. For the case in which this context will re-used, set them * to their default values. */ if (s->instr != stdin && s->instr != NULL) fclose (s->instr); if (s->logstr != stderr && s->logstr != stdout && s->logstr != NULL) fclose (s->logstr); s->instr = stdin; s->logstr = stderr; /* There's no need to resize bmpc since they will be allocated on demand. * We free them here to correct bad assumptions on the size of this * vector. */ free (s->bmpc); s->bmpc = NULL; pthread_mutex_lock (&context_factory_mutex); if (context_factory_size < MPS_CONTEXT_FACTORY_MAXIMUM_SIZE) { context_factory = mps_realloc (context_factory, sizeof(mps_context*) * (context_factory_size + 1)); context_factory[context_factory_size++] = s; pthread_mutex_unlock (&context_factory_mutex); return; } pthread_mutex_unlock (&context_factory_mutex); if (s->initialized) mps_free_data (s); mps_thread_pool_free (s, s->pool); free (s->input_config); free (s->output_config); s->active_poly = NULL; if (s->secular_equation) mps_secular_equation_free (s, MPS_POLYNOMIAL (s->secular_equation)); free (s); }