[Bugfix][Build] Patch stable string memleak fix from 2.14 for 2.13 (#51185)

Signed-off-by: Jane Xu <janeyx@meta.com>
Signed-off-by: Shengqi Chen <harry-chen@outlook.com>
Co-authored-by: Shengqi Chen <harry-chen@outlook.com>
This commit is contained in:
Jane (Yuan) Xu
2026-08-08 21:12:39 -07:00
committed by GitHub
co-authored by Shengqi Chen
parent 073c510c91
commit f8d03e7741
2 changed files with 43 additions and 0 deletions
+15
View File
@@ -0,0 +1,15 @@
diff --git a/torch/csrc/stable/stableivalue_conversions.h b/torch/csrc/stable/stableivalue_conversions.h
--- a/torch/csrc/stable/stableivalue_conversions.h
+++ b/torch/csrc/stable/stableivalue_conversions.h
@@ -807 +807 @@
-// Returns a new std::string; the string in val is deleted.
+// Returns a std::string which owns its memory; the string in val is deleted.
@@ -819 +819 @@
- auto strptr = new std::string(data, length);
+ const auto str = std::string(data, length);
@@ -821 +821 @@
- // delete the old string before returning new string
+ // delete the old string
@@ -823 +823 @@
- return *strptr;
+ return str;