Skip to content

Commit c95284d

Browse files
Avoid a resource leak down extent split failure paths.
Previously, we would leak the extent and memory associated with a salvageable portion of an extent that we were trying to split in three, in the case where the first split attempt succeeded and the second failed.
1 parent a62e42b commit c95284d

File tree

1 file changed

+8
-10
lines changed

1 file changed

+8
-10
lines changed

src/extent.c

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1319,21 +1319,19 @@ extent_grow_retained(tsdn_t *tsdn, arena_t *arena,
13191319
* cant_alloc case should not occur.
13201320
*/
13211321
assert(result == extent_split_interior_error);
1322+
if (to_salvage != NULL) {
1323+
if (config_prof) {
1324+
extent_gdump_add(tsdn, to_salvage);
1325+
}
1326+
extent_record(tsdn, arena, r_extent_hooks,
1327+
&arena->extents_retained, to_salvage, true);
1328+
}
13221329
if (to_leak != NULL) {
13231330
extent_deregister_no_gdump_sub(tsdn, to_leak);
13241331
extents_leak(tsdn, arena, r_extent_hooks,
13251332
&arena->extents_retained, to_leak, true);
1326-
goto label_err;
13271333
}
1328-
/*
1329-
* Note: we don't handle the non-NULL to_salvage case at all.
1330-
* This maintains the behavior that was present when the
1331-
* refactor pulling extent_split_interior into a helper function
1332-
* was added. I think this is actually a bug (we leak both the
1333-
* memory and the extent_t in that case), but since this code is
1334-
* getting deleted very shortly (in a subsequent commit),
1335-
* ensuring correctness down this path isn't worth the effort.
1336-
*/
1334+
goto label_err;
13371335
}
13381336

13391337
if (*commit && !extent_committed_get(extent)) {

0 commit comments

Comments
 (0)