@@ -282,28 +282,11 @@ std::int32_t RTNAME(GetEnvVariable)(const Descriptor &name,
282
282
return StatOk;
283
283
}
284
284
285
- const char *ensureNullTerminated (
286
- const char *str, size_t length, Terminator &terminator) {
287
- if (length <= strlen (str)) {
288
- char *newCmd{(char *)malloc (length + 1 )};
289
- if (newCmd == NULL ) {
290
- terminator.Crash (" Command not null-terminated, memory allocation failed "
291
- " for null-terminated newCmd." );
292
- }
293
-
294
- strncpy (newCmd, str, length);
295
- newCmd[length] = ' \0 ' ;
296
- return newCmd;
297
- } else {
298
- return str;
299
- }
300
- }
301
-
302
285
void RTNAME (System)(const Descriptor &command, const Descriptor *exitstat,
303
286
const char *sourceFile, int line) {
304
287
Terminator terminator{sourceFile, line};
305
288
306
- const char *newCmd{ensureNullTerminated (
289
+ const char *newCmd{EnsureNullTerminated (
307
290
command.OffsetElement (), command.ElementBytes (), terminator)};
308
291
int status{std::system (newCmd)};
309
292
@@ -315,6 +298,7 @@ void RTNAME(System)(const Descriptor &command, const Descriptor *exitstat,
315
298
int exitstatVal{WEXITSTATUS (status)};
316
299
StoreLengthToDescriptor (exitstat, exitstatVal, terminator);
317
300
#endif
301
+ FreeMemory ((void *)newCmd);
318
302
}
319
303
}
320
304
0 commit comments