diff options
author | Dirk Hohndel <dirk@hohndel.org> | 2015-10-03 09:44:16 -0400 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2015-10-03 09:44:16 -0400 |
commit | 69036a1bb777b3a4c6f9b6217049899c2ec267b3 (patch) | |
tree | 57669d5204ca8308eb15ca5de48f953a34d42a46 | |
parent | b2fcc7c8139742aa9a984d6f36f968bc4a9ed742 (diff) | |
download | subsurface-69036a1bb777b3a4c6f9b6217049899c2ec267b3.tar.gz |
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>
-rw-r--r-- | dive.c | 7 |
1 files changed, 4 insertions, 3 deletions
@@ -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); |