It appears the patch didn't survive some of the editing I did in reportbug. Here it is:

--- chkservice-master/src/chk-systemd.cpp 2020-01-16 01:13:08.000000000 -0400 +++ chkservice-patched/src/chk-systemd.cpp 2020-01-16 10:21:25.000000000 -0400
@@ -517,20 +517,27 @@
   }

   char *names[ids->size()];

   for (auto id : (*ids)) {
-    names[i] = (char *) id.c_str();
+    const char *name = id.c_str();
+    char *copy = new char[strlen(name)+ 1];
+    strcpy(copy, name);
+    names[i] =copy;
     i++;
   }
   names[i] = NULL;

   try {
     applyUnitState("EnableUnitFiles", names, STATE_FLAGS_ENABLE);
   } catch (std::string &err) {
+    for (i; i < 0; --i)
+           delete names[i];
     throw err;
   }
+  for (i; i < 0; --i)
+         delete names[i];
 }

 void ChkBus::disableUnits(std::set<std::string> *ids) {
   int i = 0;

@@ -539,21 +546,28 @@
   }

   char *names[ids->size()];

   for (auto id : (*ids)) {
-    names[i] = (char *) id.c_str();
+    const char *name = id.c_str();
+    char *copy = new char[strlen(name)+ 1];
+    strcpy(copy, name);
+    names[i] =copy;
     i++;
   }

   names[i] = NULL;

   try {
     applyUnitState("DisableUnitFiles", names, STATE_FLAGS_DISABLE);
   } catch (std::string &err) {
+    for (i; i < 0; --i)
+           delete names[i];
     throw err;
   }
+  for (i; i < 0; --i)
+         delete names[i];
 }

 void ChkBus::enableUnit(const char *name) {
   try {
     std::set<std::string> id;

Reply via email to