summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTim-Philipp Müller <tim@centricular.net>2013-06-28 00:04:43 +0100
committerTim-Philipp Müller <tim@centricular.net>2013-06-28 00:04:43 +0100
commitf9962a7645a7e0a173bef88d56f6d4a36efeb12e (patch)
tree226051a1dbe9e779ba106a64af9068cd75d9067a
parent169b68fea2ae673b469199495792df901e85515f (diff)
glfiltershader: fix crash when loading shader file0.10
Just use g_file_get_contents() instead of home-made file loading. Fixes two issues - one is that we should pass "r" to fopen and not O_RDONLY, the other is that an incorrect variable was used to read the file length, leading to an empty shader file. Spotted by: Wang Xin-yu (王昕宇) <comicfans44@gmail.com> https://bugzilla.gnome.org/show_bug.cgi?id=702844 https://bugzilla.gnome.org/show_bug.cgi?id=702845
-rw-r--r--gst/gl/gstglfiltershader.c40
1 files changed, 8 insertions, 32 deletions
diff --git a/gst/gl/gstglfiltershader.c b/gst/gl/gstglfiltershader.c
index 81e6674..73c1d5a 100644
--- a/gst/gl/gstglfiltershader.c
+++ b/gst/gl/gstglfiltershader.c
@@ -254,44 +254,20 @@ gst_gl_filtershader_get_property (GObject * object, guint prop_id,
}
static int
-gst_gl_filtershader_load_file (char *filename, char **storage)
+gst_gl_filtershader_load_file (const gchar * filename, gchar ** storage)
{
+ GError *err = NULL;
+ gchar *old_storage = *storage;
- size_t count;
- size_t bytes;
- FILE *f;
-
- // read the filter from file
GST_INFO ("loading file: %s", filename);
- f = fopen (filename, O_RDONLY);
- if (f == NULL) {
- GST_ERROR ("could not open file: %s", filename);
- return -1;
- }
-
- if (*storage) {
- g_free (*storage);
- *storage = 0;
- }
-
- count = fseek (f, 0, SEEK_END);
- *storage = g_malloc (count + 1);
- if (!*storage) {
- GST_ERROR ("g_malloc failed: %lud", (gulong) count);
- return -1;
- }
-
- fseek (f, 0, SEEK_SET);
- bytes = fread ((void *) *storage, sizeof (char), count, f);
- if (bytes != count) {
- GST_ERROR ("read failed: %lud/%lud", (gulong) bytes, (gulong) count);
+ if (!g_file_get_contents (filename, storage, NULL, &err)) {
+ GST_ERROR ("could not open file '%s':", filename, err->message);
+ g_error_free (err);
return -1;
}
- ((char *) *storage)[count] = 0;
- if (f)
- fclose (f);
- GST_INFO ("read: %lud", (gulong) bytes);
+ g_free (old_storage);
+ GST_INFO ("read: %d bytes", (int) strlen (*storage));
return 0;
}