tfix memory handling around grain creation - granular - granular dynamics simulation
 (HTM) git clone git://src.adamsgaard.dk/granular
 (DIR) Log
 (DIR) Files
 (DIR) Refs
 (DIR) README
 (DIR) LICENSE
       ---
 (DIR) commit 054a2cc1416d4760f8a25499d5db265877f4d359
 (DIR) parent 6660be16da098a733430dda22a591fe97657adcf
 (HTM) Author: Anders Damsgaard <anders@adamsgaard.dk>
       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(-)
       ---
 (DIR) 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;
        }
        
 (DIR) 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);
 (DIR) diff --git a/simulation.c b/simulation.c
       t@@ -1 +1,7 @@
        #include "simulation.h"
       +
       +void
       +free_sim(struct simulation *sim)
       +{
       +        free(sim->grains);
       +}