[Xfce4-commits] [xfce/xfdesktop] 01/02: Fix for crash in xfdesktop_backdrop_list_choose_random (Bug #11346)
noreply at xfce.org
noreply at xfce.org
Sun Apr 12 18:22:18 CEST 2015
This is an automated email from the git hooks/post-receive script.
eric pushed a commit to branch xfce-4.10
in repository xfce/xfdesktop.
commit 7d82ff42f310c56a1968ed97cf5c09be4827d65e
Author: Eric Koegel <eric.koegel at gmail.com>
Date: Sun Feb 15 11:05:51 2015 +0300
Fix for crash in xfdesktop_backdrop_list_choose_random (Bug #11346)
This patch some issues with the function:
- backdrop.list file containing only the "# xfce backdrop list" line
- leak of empty string(s) at the end
- freed pointer kept in the resulting array
Patch submitted by ericdf
Signed-off-by: Eric Koegel <eric.koegel at gmail.com>
---
common/xfdesktop-common.c | 31 ++++++++++++++++++++-----------
1 file changed, 20 insertions(+), 11 deletions(-)
diff --git a/common/xfdesktop-common.c b/common/xfdesktop-common.c
index 2b8e80b..dfb16c0 100644
--- a/common/xfdesktop-common.c
+++ b/common/xfdesktop-common.c
@@ -102,26 +102,35 @@ xfdesktop_backdrop_list_load(const gchar *filename,
items = 0;
files = g_strsplit(contents, "\n", -1);
+ g_free(contents); /* not needed anymore */
+
/* Since the first line is the file identifier, we need to skip it.
* Additionally, we want to skip blank lines. */
- for(i = 1; files[i] != NULL; i++) {
- if(g_strcmp0(files[i], "") != 0) {
- g_free(files[items]);
- files[items] = g_strdup(files[i]);
- DBG("files[items] %s", files[items]);
- items++;
+
+ /* a file with just the header will have only one line */
+ if(files[0] != NULL)
+ {
+ g_free(files[0]); /* that's the only non-empty line we need to remove */
+ files[0] = NULL;
+ for(i = 1; files[i] != NULL; i++) {
+ if(g_strcmp0(files[i], "") != 0) {
+ files[items]=files[i]; /* move the string to the current item slot */
+
+ items++;
+ } else {
+ g_free(files[i]); /* free the irrelevant empty string */
+ }
}
- }
- files[items+1] = NULL;
+ files[items] = NULL; /* set the sentinel */
- files = g_realloc(files, sizeof(gchar *) * (items+1));
+ /* resize */
+ files = g_realloc(files, sizeof(gchar *) * (items+1));
+ }
DBG("items %d", items);
if(n_items)
*n_items = items;
- g_free(contents);
-
return files;
}
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.
More information about the Xfce4-commits
mailing list