mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
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:
parent
b2fcc7c813
commit
69036a1bb7
1 changed files with 4 additions and 3 deletions
7
dive.c
7
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);
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue