From 813e1ffd9654e3d86870ea831ea5830320077ba4 Mon Sep 17 00:00:00 2001 From: Pablo Barciela Date: Fri, 24 Aug 2018 22:49:08 +0200 Subject: pluma-document: fix possible memory leak --- pluma/pluma-document.c | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/pluma/pluma-document.c b/pluma/pluma-document.c index 9cc305d8..1e9ca819 100644 --- a/pluma/pluma-document.c +++ b/pluma/pluma-document.c @@ -656,9 +656,8 @@ file_with_bom (GFile *file) FILE *testfile; gchar c; int i; - gchar *bom; + gchar bom[3]; gchar *file_path; - gboolean has_bom; file_path = g_file_get_path (file); @@ -672,8 +671,6 @@ file_with_bom (GFile *file) return FALSE; } - bom = ""; - for (i = 0; i < 3; i++) { c = fgetc (testfile); @@ -681,18 +678,17 @@ file_with_bom (GFile *file) if (c == EOF) break; else - bom = g_strdup_printf ("%s%c", bom, c); + bom[i] = c; } fclose (testfile); - if (g_strcmp0 (bom, "\357\273\277") == 0) - has_bom = TRUE; + if ((bom[0] == '\357') && + (bom[1] == '\273') && + (bom[2] == '\277')) + return TRUE; else - has_bom = FALSE; - - g_free (bom); - return has_bom; + return FALSE; } static void -- cgit v1.2.1