stardis

Perform coupled heat transfer calculations
git clone git://git.meso-star.fr/stardis.git
Log | Files | Refs | README | LICENSE

commit 580c13150738b78675bcf046dbd9b98a35d8ac63
parent dde552666573b5bb75f7aceea0735e3d4b6ddb71
Author: Christophe Coustet <christophe.coustet@meso-star.com>
Date:   Fri, 10 May 2019 11:44:49 +0200

Fix mem corruption

Diffstat:
Msrc/stardis-app.c | 2++
Msrc/stardis-compute.c | 7+++----
Mtinyexpr/tinyexpr.c | 13+++++++++++++
Mtinyexpr/tinyexpr.h | 2++
4 files changed, 20 insertions(+), 4 deletions(-)

diff --git a/src/stardis-app.c b/src/stardis-app.c @@ -936,9 +936,11 @@ stardis_release(struct stardis* stardis) case DESC_BOUND_T_FOR_SOLID: case DESC_BOUND_T_FOR_FLUID: free(desc->d.t_boundary.T); + te_free(desc->d.t_boundary.te_temperature); break; case DESC_BOUND_F_FOR_SOLID: free(desc->d.f_boundary.flux); + te_free(desc->d.f_boundary.te_flux); break; default: FATAL("Invalid type.\n"); } diff --git a/src/stardis-compute.c b/src/stardis-compute.c @@ -198,7 +198,6 @@ solid_dont_get_temperature fflush(stdout); fflush(stderr); FATAL("solid_dont_get_temperature: path went to a non-existing medium\n"); - return 0; } static double @@ -1031,7 +1030,8 @@ stardis_compute(struct stardis* stardis, enum stardis_mode mode) interface_shader.back.temperature = interface_get_temperature; } ASSERT(connect->d.t_boundary.te_temperature); - interface_props->temperature = connect->d.t_boundary.te_temperature; + interface_props->temperature + = te_duplicate(connect->d.t_boundary.te_temperature); if (connect->d.t_boundary.has_hc) { ASSERT(connect->type == DESC_BOUND_T_FOR_FLUID); interface_shader.convection_coef = interface_get_convection_coef; @@ -1056,7 +1056,7 @@ stardis_compute(struct stardis* stardis, enum stardis_mode mode) interface_shader.back.flux = interface_get_flux; } ASSERT(connect->d.f_boundary.te_flux); - interface_props->flux = connect->d.f_boundary.te_flux; + interface_props->flux = te_duplicate(connect->d.f_boundary.te_flux); break; case DESC_SOLID_FLUID_CONNECT: /* Both front and back should be defined; @@ -1306,7 +1306,6 @@ stardis_compute(struct stardis* stardis, enum stardis_mode mode) end: if (data) SDIS(data_ref_put(data)); if (interfaces) { - for (i = 0; i < sa_size(interfaces); ++i) SDIS(interface_ref_put(interfaces[i])); sa_release(interfaces); diff --git a/tinyexpr/tinyexpr.c b/tinyexpr/tinyexpr.c @@ -133,6 +133,19 @@ static te_expr *new_expr1(const int type, te_expr *p1) { return ret; } +te_expr* te_duplicate(te_expr* n) { + const size_t size = sizeof(te_expr) +#ifndef TE_WITHOUT_CLOSURES + + (IS_CLOSURE(n->type) ? sizeof(void*) : 0); +#endif + ; + te_expr* nn; + assert(n); + nn = malloc(size); + memcpy(nn, n, size); + return nn; +} + static te_expr *new_expr2(const int type, te_expr *p1, te_expr *p2) { const size_t size = sizeof(te_expr) + sizeof(void*) #ifndef TE_WITHOUT_CLOSURES diff --git a/tinyexpr/tinyexpr.h b/tinyexpr/tinyexpr.h @@ -187,6 +187,8 @@ void te_print(const te_expr *n); /* This is safe to call on NULL pointers. */ void te_free(te_expr *n); +/* Duplicates a te_expr */ +te_expr* te_duplicate(te_expr* n); #ifdef __cplusplus }