diff options
author | Jussi Kivilinna <jussi.kivilinna@iki.fi> | 2022-02-13 14:07:49 +0100 |
---|---|---|
committer | Jussi Kivilinna <jussi.kivilinna@iki.fi> | 2022-03-08 19:00:31 +0100 |
commit | 583b664a07b41ba6991f87a811ab933990457063 (patch) | |
tree | e2fe61a0e84b8b9ce4c5e173bd3ddac03f732572 /g10/plaintext.c | |
parent | Use iobuf buffer size for temporary buffer size (diff) | |
download | gnupg2-583b664a07b41ba6991f87a811ab933990457063.tar.xz gnupg2-583b664a07b41ba6991f87a811ab933990457063.zip |
g10/plaintext: disable estream buffering in binary mode
* g10/plaintext.c (handle_plaintext): Disable estream buffering in
binary modes.
--
Since in binary mode, large buffers are passed from source iobuf to
target estream, extra buffering in estream only causes extra memory
copying and overhead.
GnuPG-bug-id: T5828
Signed-off-by: Jussi Kivilinna <jussi.kivilinna@iki.fi>
Diffstat (limited to 'g10/plaintext.c')
-rw-r--r-- | g10/plaintext.c | 24 |
1 files changed, 23 insertions, 1 deletions
diff --git a/g10/plaintext.c b/g10/plaintext.c index a1bbbd95f..5c21dd7f6 100644 --- a/g10/plaintext.c +++ b/g10/plaintext.c @@ -292,7 +292,22 @@ handle_plaintext (PKT_plaintext * pt, md_filter_context_t * mfx, else /* Binary mode. */ { size_t temp_size = iobuf_set_buffer_size(0) * 1024; - byte *buffer = xmalloc (temp_size); + byte *buffer; + + if (fp) + { + /* Disable buffering in estream as we are passing large + * buffers to es_fwrite. */ + es_setbuf (fp, NULL); + } + + buffer = xmalloc (temp_size); + if (!buffer) + { + err = gpg_error_from_syserror (); + goto leave; + } + while (pt->len) { int len = pt->len > temp_size ? temp_size : pt->len; @@ -371,6 +386,13 @@ handle_plaintext (PKT_plaintext * pt, md_filter_context_t * mfx, byte *buffer; int eof_seen = 0; + if (fp) + { + /* Disable buffering in estream as we are passing large + * buffers to es_fwrite. */ + es_setbuf (fp, NULL); + } + buffer = xtrymalloc (temp_size); if (!buffer) { |