[glib] gio: Use heap-allocated buffer



commit 0106a6cd9ea1403b994e5f879fc6433e32ec304b
Author: Bastien Nocera <hadess hadess net>
Date:   Wed Dec 7 14:47:58 2016 +0100

    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

 gio/gfile.c |    8 ++++++--
 1 files changed, 6 insertions(+), 2 deletions(-)
---
diff --git a/gio/gfile.c b/gio/gfile.c
index a1c80d3..218d9af 100644
--- a/gio/gfile.c
+++ b/gio/gfile.c
@@ -2765,6 +2765,8 @@ g_file_copy_attributes (GFile           *source,
   return res;
 }
 
+#define STREAM_BUFFER_SIZE (1024*64)
+
 static gboolean
 copy_stream_with_progress (GInputStream           *in,
                            GOutputStream          *out,
@@ -2776,7 +2778,7 @@ copy_stream_with_progress (GInputStream           *in,
 {
   gssize n_read, n_written;
   goffset current_size;
-  char buffer[1024*64], *p;
+  char *buffer, *p;
   gboolean res;
   goffset total_size;
   GFileInfo *info;
@@ -2813,11 +2815,12 @@ copy_stream_with_progress (GInputStream           *in,
   if (total_size == -1)
     total_size = 0;
 
+  buffer = g_malloc0 (STREAM_BUFFER_SIZE);
   current_size = 0;
   res = 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)
         {
           res = FALSE;
@@ -2849,6 +2852,7 @@ copy_stream_with_progress (GInputStream           *in,
       if (progress_callback)
         progress_callback (current_size, total_size, progress_callback_data);
     }
+  g_free (buffer);
 
   /* Make sure we send full copied size */
   if (progress_callback)


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]