summaryrefslogtreecommitdiff
path: root/gtk/gtkaccelmap.c
diff options
context:
space:
mode:
authorOwen Taylor <otaylor@redhat.com>2002-03-22 16:06:06 +0000
committerOwen Taylor <otaylor@src.gnome.org>2002-03-22 16:06:06 +0000
commitabfed60cab0d6f9440430d05926b1e1e3d5b9cc9 (patch)
tree866c8232a0e3bfb5db4d0cc4d37f0375e0ffb100 /gtk/gtkaccelmap.c
parent771e2d573cc23b8cc6b4e48f2cab05d64d94a9b4 (diff)
downloadgtk+-abfed60cab0d6f9440430d05926b1e1e3d5b9cc9.tar.gz
Fix memory leak. (#74400, Morten Welinder.)
Fri Mar 22 10:56:19 2002 Owen Taylor <otaylor@redhat.com> * gtk/gtkaccelmap.c (gtk_accel_map_save_fd): Fix memory leak. (#74400, Morten Welinder.) * gtk/gtkaccelmap.c: Properly handle short returns from write() calls. (Handling EINTR isn't enough... that only handles the case where you were interrupted before you wrote a single byte.) * gdk/linux-fb/gdkmouse-fb.c gdk/linux-fb/gdkkeyboard-fb.c: Robustify against short returns from write() calls.
Diffstat (limited to 'gtk/gtkaccelmap.c')
-rw-r--r--gtk/gtkaccelmap.c37
1 files changed, 29 insertions, 8 deletions
diff --git a/gtk/gtkaccelmap.c b/gtk/gtkaccelmap.c
index 3bafd1ce4e..3c1058047b 100644
--- a/gtk/gtkaccelmap.c
+++ b/gtk/gtkaccelmap.c
@@ -24,6 +24,7 @@
#include "gtkwindow.h" /* in lack of GtkAcceleratable */
#include <string.h>
+#include <errno.h>
#include <fcntl.h>
#ifdef HAVE_UNISTD_H
#include <unistd.h>
@@ -586,6 +587,29 @@ gtk_accel_map_load (const gchar *file_name)
close (fd);
}
+static gboolean
+write_all (gint fd,
+ gchar *buf,
+ gsize to_write)
+{
+ while (to_write > 0)
+ {
+ gssize count = write (fd, buf, to_write);
+ if (count < 0)
+ {
+ if (errno != EINTR)
+ return FALSE;
+ }
+ else
+ {
+ to_write -= count;
+ buf += count;
+ }
+ }
+
+ return TRUE;
+}
+
static void
accel_map_print (gpointer data,
const gchar *accel_path,
@@ -594,7 +618,7 @@ accel_map_print (gpointer data,
gboolean changed)
{
GString *gstring = g_string_new (changed ? NULL : "; ");
- gint err, fd = GPOINTER_TO_INT (data);
+ gint fd = GPOINTER_TO_INT (data);
gchar *tmp, *name;
g_string_append (gstring, "(gtk_accel_path \"");
@@ -613,9 +637,7 @@ accel_map_print (gpointer data,
g_string_append (gstring, "\")\n");
- do
- err = write (fd, gstring->str, gstring->len);
- while (err < 0 && errno == EINTR);
+ write_all (fd, gstring->str, gstring->len);
g_string_free (gstring, TRUE);
}
@@ -632,7 +654,6 @@ void
gtk_accel_map_save_fd (gint fd)
{
GString *gstring;
- gint err;
g_return_if_fail (fd >= 0);
@@ -643,9 +664,9 @@ gtk_accel_map_save_fd (gint fd)
g_string_append (gstring, "; this file is an automated accelerator map dump\n");
g_string_append (gstring, ";\n");
- do
- err = write (fd, gstring->str, gstring->len);
- while (err < 0 && errno == EINTR);
+ write_all (fd, gstring->str, gstring->len);
+
+ g_string_free (gstring, TRUE);
gtk_accel_map_foreach (GINT_TO_POINTER (fd), accel_map_print);
}