tfix memory handling around grain creation - granular - granular dynamics simul… | |
git clone git://src.adamsgaard.dk/granular | |
Log | |
Files | |
Refs | |
README | |
LICENSE | |
--- | |
commit 054a2cc1416d4760f8a25499d5db265877f4d359 | |
parent 6660be16da098a733430dda22a591fe97657adcf | |
Author: Anders Damsgaard <[email protected]> | |
Date: Thu, 18 Mar 2021 14:33:18 +0100 | |
fix memory handling around grain creation | |
Diffstat: | |
M grain.c | 6 +++--- | |
M grain.h | 2 +- | |
M simulation.c | 6 ++++++ | |
3 files changed, 10 insertions(+), 4 deletions(-) | |
--- | |
diff --git a/grain.c b/grain.c | |
t@@ -9,11 +9,11 @@ | |
#define FLOATPREC 17 | |
-struct grain * | |
+struct grain | |
grain_new(void) | |
{ | |
- struct grain *g = malloc(sizeof(*g)); | |
- grain_defaults(g); | |
+ struct grain g; | |
+ grain_defaults(&g); | |
return g; | |
} | |
diff --git a/grain.h b/grain.h | |
t@@ -35,7 +35,7 @@ struct grain { | |
size_t color; | |
}; | |
-struct grain * grain_new(void); | |
+struct grain grain_new(void); | |
void grain_defaults(struct grain *g); | |
void grain_print(FILE *stream, const struct grain *g); | |
diff --git a/simulation.c b/simulation.c | |
t@@ -1 +1,7 @@ | |
#include "simulation.h" | |
+ | |
+void | |
+free_sim(struct simulation *sim) | |
+{ | |
+ free(sim->grains); | |
+} |