]> git.tdb.fi Git - ext/subsurface.git/blobdiff - dive.c
Fixed another memory leak
[ext/subsurface.git] / dive.c
diff --git a/dive.c b/dive.c
index 3774ba80d037d77b9077a48e42fea16077cf50bc..a420a3ef638927cd39c60ffe69f5fa37a9bbfea3 100644 (file)
--- a/dive.c
+++ b/dive.c
@@ -120,6 +120,28 @@ double get_depth_units(unsigned int mm, int *frac, const char **units)
        return d;
 }
 
+double get_weight_units(unsigned int grams, int *frac, const char **units)
+{
+       int decimals;
+       double value;
+       const char* unit;
+
+       if (output_units.weight == LBS) {
+               value = grams_to_lbs(grams);
+               unit = "lbs";
+               decimals = 0;
+       } else {
+               value = grams / 1000.0;
+               unit = "kg";
+               decimals = 1;
+       }
+       if (frac)
+               *frac = decimals;
+       if (units)
+               *units = unit;
+       return value;
+}
+
 struct dive *alloc_dive(void)
 {
        const int initial_samples = 5;
@@ -160,7 +182,7 @@ struct sample *prepare_sample(struct dive **divep)
        return NULL;
 }
 
-void finish_sample(struct dive *dive, struct sample *sample)
+void finish_sample(struct dive *dive)
 {
        dive->samples++;
 }
@@ -472,6 +494,10 @@ struct dive *fixup_dive(struct dive *dive)
                if (same_rounded_pressure(cyl->sample_end, cyl->end))
                        cyl->end.mbar = 0;
        }
+       for (i = 0; i < MAX_WEIGHTSYSTEMS; i++) {
+               weightsystem_t *ws = dive->weightsystem + i;
+               add_weightsystem_description(ws);
+       }
 
        return dive;
 }
@@ -490,7 +516,7 @@ static struct dive *add_sample(struct sample *sample, int time, struct dive *div
                return NULL;
        *p = *sample;
        p->time.seconds = time;
-       finish_sample(dive, p);
+       finish_sample(dive);
        return dive;
 }