mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2025-12-24 18:20:07 +01:00
core: pre-allocate exact buffer size for output in nm_utils_spawn_helper()
It's easy enough to know how many bytes are needed. Just allocate the right size (+1, because NMStrBuf really likes to reserve that extra byte for the trailing NUL, even if it's not needed in this case).
This commit is contained in:
parent
346196792c
commit
a65e80e8b6
1 changed files with 4 additions and 1 deletions
|
|
@ -5099,6 +5099,7 @@ nm_utils_spawn_helper(const char *const *args,
|
|||
int fd_flags;
|
||||
const char *const *arg;
|
||||
GMainContext *context;
|
||||
gsize n;
|
||||
|
||||
nm_assert(args && args[0]);
|
||||
|
||||
|
|
@ -5176,7 +5177,9 @@ nm_utils_spawn_helper(const char *const *args,
|
|||
fcntl(info->child_stderr, F_SETFL, fd_flags | O_NONBLOCK);
|
||||
|
||||
/* Watch process stdin */
|
||||
info->out_buffer = NM_STR_BUF_INIT(NM_UTILS_GET_NEXT_REALLOC_SIZE_40, TRUE);
|
||||
for (n = 1, arg = args; *arg; arg++)
|
||||
n += strlen(*arg) + 1u;
|
||||
info->out_buffer = NM_STR_BUF_INIT(n, TRUE);
|
||||
for (arg = args; *arg; arg++) {
|
||||
nm_str_buf_append(&info->out_buffer, *arg);
|
||||
nm_str_buf_append_c(&info->out_buffer, '\0');
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue