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 <dirk@hohndel.org>
This commit is contained in:
Dirk Hohndel 2015-10-03 09:44:16 -04:00
parent b2fcc7c813
commit 69036a1bb7

7
dive.c
View file

@ -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);