mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2024-12-26 15:36:14 +01:00
gio: Use heap-allocated buffer
As if we were to increase the buffer size, it would be a bit too big to fit on the stack. https://bugzilla.gnome.org/show_bug.cgi?id=773823
This commit is contained in:
parent
6dfc6fee7b
commit
0106a6cd9e
@ -2765,6 +2765,8 @@ g_file_copy_attributes (GFile *source,
|
|||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#define STREAM_BUFFER_SIZE (1024*64)
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
copy_stream_with_progress (GInputStream *in,
|
copy_stream_with_progress (GInputStream *in,
|
||||||
GOutputStream *out,
|
GOutputStream *out,
|
||||||
@ -2776,7 +2778,7 @@ copy_stream_with_progress (GInputStream *in,
|
|||||||
{
|
{
|
||||||
gssize n_read, n_written;
|
gssize n_read, n_written;
|
||||||
goffset current_size;
|
goffset current_size;
|
||||||
char buffer[1024*64], *p;
|
char *buffer, *p;
|
||||||
gboolean res;
|
gboolean res;
|
||||||
goffset total_size;
|
goffset total_size;
|
||||||
GFileInfo *info;
|
GFileInfo *info;
|
||||||
@ -2813,11 +2815,12 @@ copy_stream_with_progress (GInputStream *in,
|
|||||||
if (total_size == -1)
|
if (total_size == -1)
|
||||||
total_size = 0;
|
total_size = 0;
|
||||||
|
|
||||||
|
buffer = g_malloc0 (STREAM_BUFFER_SIZE);
|
||||||
current_size = 0;
|
current_size = 0;
|
||||||
res = TRUE;
|
res = TRUE;
|
||||||
while (TRUE)
|
while (TRUE)
|
||||||
{
|
{
|
||||||
n_read = g_input_stream_read (in, buffer, sizeof (buffer), cancellable, error);
|
n_read = g_input_stream_read (in, buffer, STREAM_BUFFER_SIZE, cancellable, error);
|
||||||
if (n_read == -1)
|
if (n_read == -1)
|
||||||
{
|
{
|
||||||
res = FALSE;
|
res = FALSE;
|
||||||
@ -2849,6 +2852,7 @@ copy_stream_with_progress (GInputStream *in,
|
|||||||
if (progress_callback)
|
if (progress_callback)
|
||||||
progress_callback (current_size, total_size, progress_callback_data);
|
progress_callback (current_size, total_size, progress_callback_data);
|
||||||
}
|
}
|
||||||
|
g_free (buffer);
|
||||||
|
|
||||||
/* Make sure we send full copied size */
|
/* Make sure we send full copied size */
|
||||||
if (progress_callback)
|
if (progress_callback)
|
||||||
|
Loading…
Reference in New Issue
Block a user