[clang] c3c8f16 - Fixing the memory leak using split() instead of strtok

Abhina Sreeskantharajan via cfe-commits cfe-commits at lists.llvm.org
Tue Aug 22 12:27:03 PDT 2023


Author: Harini Chilamantula
Date: 2023-08-22T15:26:34-04:00
New Revision: c3c8f16fc32cccf5239a2aedd10c6be9babf2945

URL: https://github.com/llvm/llvm-project/commit/c3c8f16fc32cccf5239a2aedd10c6be9babf2945
DIFF: https://github.com/llvm/llvm-project/commit/c3c8f16fc32cccf5239a2aedd10c6be9babf2945.diff

LOG: Fixing the memory leak using split() instead of strtok

Reviewed By: abhina.sreeskantharajan

Differential Revision: https://reviews.llvm.org/D158254

Added: 
    

Modified: 
    clang/lib/Driver/ToolChains/ZOS.cpp

Removed: 
    


################################################################################
diff  --git a/clang/lib/Driver/ToolChains/ZOS.cpp b/clang/lib/Driver/ToolChains/ZOS.cpp
index db10567ca28ec2..05548fbec68b63 100644
--- a/clang/lib/Driver/ToolChains/ZOS.cpp
+++ b/clang/lib/Driver/ToolChains/ZOS.cpp
@@ -188,11 +188,10 @@ void zos::Linker::ConstructJob(Compilation &C, const JobAction &JA,
       CmdArgs.push_back(
           Args.MakeArgString("//'" + LEHLQ + ".SCEELIB(CELQS003)'"));
     } else {
-      char *ld_side_deck = strdup(ld_env_var.str().c_str());
-      ld_side_deck = strtok(ld_side_deck, ":");
-      while (ld_side_deck != nullptr) {
-        CmdArgs.push_back(ld_side_deck);
-        ld_side_deck = strtok(nullptr, ":");
+      SmallVector<StringRef> ld_side_deck;
+      ld_env_var.split(ld_side_deck, ":");
+      for (StringRef ld_loc : ld_side_deck) {
+        CmdArgs.push_back((ld_loc.str()).c_str());
       }
     }
   }


        


More information about the cfe-commits mailing list