From 69036a1bb777b3a4c6f9b6217049899c2ec267b3 Mon Sep 17 00:00:00 2001 From: Dirk Hohndel Date: Sat, 3 Oct 2015 09:44:16 -0400 Subject: [PATCH] Avoid resource leak by bailing early While in the current use this won't happen, if someone were to call split_dive_at with a dive that's not in the dive_table, let's bail right away before doing any work. Coverity CID 1325517 1325518 Signed-off-by: Dirk Hohndel --- dive.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/dive.c b/dive.c index a10f18520..236485160 100644 --- a/dive.c +++ b/dive.c @@ -2856,6 +2856,10 @@ static int split_dive_at(struct dive *dive, int a, int b) struct divecomputer *dc1, *dc2; struct event *event, **evp; + /* if we can't find the dive in the dive list, don't bother */ + if ((i = get_divenr(dive)) < 0) + return 0; + /* We're not trying to be efficient here.. */ d1 = create_new_copy(dive); d2 = create_new_copy(dive); @@ -2916,9 +2920,6 @@ static int split_dive_at(struct dive *dive, int a, int b) add_dive_to_trip(d2, dive->divetrip); } - if ((i = get_divenr(dive)) < 0) - return 0; - delete_single_dive(i); add_single_dive(i, d1);