From 06d6c9219b6b31db6556d8b39e027b41125881b6 Mon Sep 17 00:00:00 2001 From: zoecarver Date: Mon, 31 Oct 2022 15:01:28 -0700 Subject: [PATCH] [astgen] Fix two use-after-frees. --- lib/AST/CASTBridging.cpp | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/lib/AST/CASTBridging.cpp b/lib/AST/CASTBridging.cpp index c9f4c14a1790c..0bd565f008521 100644 --- a/lib/AST/CASTBridging.cpp +++ b/lib/AST/CASTBridging.cpp @@ -120,17 +120,19 @@ void *SwiftIdentifierExpr_create(void *ctx, BridgedIdentifier base, void *loc) { void *SwiftStringLiteralExpr_create(void *ctx, const uint8_t *_Nullable string, long len, void *TokenLoc) { ASTContext &Context = *static_cast(ctx); - return new (Context) StringLiteralExpr( - StringRef{reinterpret_cast(string), size_t(len)}, - getSourceLocFromPointer(TokenLoc)); + auto stringRef = Context.AllocateCopy( + StringRef{reinterpret_cast(string), size_t(len)}); + return new (Context) + StringLiteralExpr(stringRef, getSourceLocFromPointer(TokenLoc)); } void *SwiftIntegerLiteralExpr_create(void *ctx, const uint8_t *_Nullable string, long len, void *TokenLoc) { ASTContext &Context = *static_cast(ctx); - return new (Context) IntegerLiteralExpr( - StringRef{reinterpret_cast(string), size_t(len)}, - getSourceLocFromPointer(TokenLoc)); + auto stringRef = Context.AllocateCopy( + StringRef{reinterpret_cast(string), size_t(len)}); + return new (Context) + IntegerLiteralExpr(stringRef, getSourceLocFromPointer(TokenLoc)); } void *SwiftBooleanLiteralExpr_create(void *ctx, bool value, void *TokenLoc) {