Skip to content

Commit

Permalink
fix free-after-use.
Browse files Browse the repository at this point in the history
fix reset for `references` and `payload`.
  • Loading branch information
syoyo committed Oct 29, 2023
1 parent c266cfe commit 0e9d301
Showing 1 changed file with 11 additions and 10 deletions.
21 changes: 11 additions & 10 deletions src/composition.cc
Original file line number Diff line number Diff line change
Expand Up @@ -468,8 +468,7 @@ bool CompositeSublayersRec(AssetResolutionResolver &resolver,
if (composited_layer->has_primspec(prim.first)) {
// Skip
} else {
if (!composited_layer->emplace_primspec(prim.first,
std::move(prim.second))) {
if (!composited_layer->emplace_primspec(prim.first, std::move(prim.second))) {
PUSH_ERROR_AND_RETURN(
fmt::format("Compositing PrimSpec {} in {} failed.", prim.first,
layer_filepath));
Expand All @@ -483,8 +482,7 @@ bool CompositeSublayersRec(AssetResolutionResolver &resolver,
if (composited_layer->has_primspec(prim.first)) {
// Skip
} else {
if (!composited_layer->emplace_primspec(prim.first,
std::move(prim.second))) {
if (!composited_layer->emplace_primspec(prim.first, std::move(prim.second))) {
PUSH_ERROR_AND_RETURN(
fmt::format("Compositing PrimSpec {} in {} failed.", prim.first,
layer_filepath));
Expand Down Expand Up @@ -777,10 +775,11 @@ bool CompositeReferencesRec(uint32_t depth, AssetResolutionResolver &resolver,
}
}

// Remove `references`.
primspec.metas().references = nonstd::nullopt;
}

// Remove `references`.
primspec.metas().references.reset();

return true;
}

Expand Down Expand Up @@ -816,6 +815,7 @@ bool CompositePayloadRec(uint32_t depth, AssetResolutionResolver &resolver,
std::string asset_path = pl.asset_path.GetAssetPath();
DCOUT("asset_path = " << asset_path);

Layer layer;
const PrimSpec *src_ps{nullptr};

if (pl.asset_path.GetAssetPath().empty()) {
Expand All @@ -833,7 +833,6 @@ bool CompositePayloadRec(uint32_t depth, AssetResolutionResolver &resolver,
}
} else {

Layer layer;
if (!LoadAsset(resolver, cwp, search_paths, options.fileformats,
pl.asset_path, pl.prim_path, &layer, &src_ps,
/* error_when_no_prims_found */ true,
Expand Down Expand Up @@ -879,6 +878,7 @@ bool CompositePayloadRec(uint32_t depth, AssetResolutionResolver &resolver,
for (const auto &pl : payloads) {
std::string asset_path = pl.asset_path.GetAssetPath();

Layer layer;
const PrimSpec *src_ps{nullptr};

if (pl.asset_path.GetAssetPath().empty()) {
Expand All @@ -895,7 +895,7 @@ bool CompositePayloadRec(uint32_t depth, AssetResolutionResolver &resolver,
pl.prim_path.full_path_name()));
}
} else {
Layer layer;

if (!LoadAsset(resolver, cwp, search_paths, options.fileformats,
pl.asset_path, pl.prim_path, &layer, &src_ps,
/* error_when_no_prims_found */ true,
Expand Down Expand Up @@ -928,10 +928,11 @@ bool CompositePayloadRec(uint32_t depth, AssetResolutionResolver &resolver,
}
}

// Remove `payload`.
primspec.metas().payload = nonstd::nullopt;
}

// Remove `payload`.
primspec.metas().payload.reset();

return true;
}

Expand Down

0 comments on commit 0e9d301

Please sign in to comment.