[PATCH] D158254: Fixing the memory leak using split() instead of strtok

Harini Chilamantula via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri Aug 18 00:28:12 PDT 2023


hchilama created this revision.
hchilama created this object with edit policy "Administrators".
Herald added a project: All.
hchilama requested review of this revision.
Herald added subscribers: cfe-commits, MaskRay.
Herald added a project: clang.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D158254

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


Index: clang/lib/Driver/ToolChains/ZOS.cpp
===================================================================
--- clang/lib/Driver/ToolChains/ZOS.cpp
+++ clang/lib/Driver/ToolChains/ZOS.cpp
@@ -188,11 +188,10 @@
       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());
       }
     }
   }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D158254.551408.patch
Type: text/x-patch
Size: 772 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230818/4f1fdb7e/attachment.bin>


More information about the cfe-commits mailing list