From: Tom Tromey Date: Tue, 4 May 2021 21:26:58 +0000 (-0600) Subject: libcc1: fix a memory leak X-Git-Tag: upstream/12.2.0~8226 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=ee75ca6b72e4235aa48d6fb30c5cd274f2ff6b67;p=platform%2Fupstream%2Fgcc.git libcc1: fix a memory leak libcc1 has a memory leak when calling fork_exec -- it allocates a new vector of arguments, but then does not free it anywhere. This patch changes this code to use std::vector instead. Note that the previous code tried to avoid bad_alloc. I don't believe this is very important. For one thing, plenty of other allocations do not bother with this. libcc1 * gdbctx.hh (do_compile): Use std::vector. --- diff --git a/libcc1/gdbctx.hh b/libcc1/gdbctx.hh index 4a48381..4d24883 100644 --- a/libcc1/gdbctx.hh +++ b/libcc1/gdbctx.hh @@ -308,15 +308,11 @@ namespace cc1_plugin self->add_callbacks (); - char **argv = new (std::nothrow) char *[self->args.size () + 1]; - if (argv == NULL) - return 0; - + std::vector argv (self->args.size () + 1); for (unsigned int i = 0; i < self->args.size (); ++i) argv[i] = const_cast (self->args[i].c_str ()); - argv[self->args.size ()] = NULL; - return self->fork_exec (argv, fds, stderr_fds); + return self->fork_exec (argv.data (), fds, stderr_fds); } static int