summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRichard Hughes <richard@hughsie.com>2015-08-26 08:20:09 +0100
committerRichard Hughes <richard@hughsie.com>2015-08-26 08:20:09 +0100
commitccf79b98c3208871e4a2cc0fe9889ef8ad6e6737 (patch)
tree7336e425be93769d7e32f79f3860760c6eee07b5
parent692fef57a89cf040c539435ca444c5f9ab58f3d9 (diff)
parent94ec7a292a4b8a75c9e576acfbe9518ecea681fa (diff)
downloadappstream-glib-ccf79b98c3208871e4a2cc0fe9889ef8ad6e6737.tar.gz
Merge pull request #59 from pinotree/path_max
Avoid using PATH_MAX
-rw-r--r--libappstream-builder/asb-self-test.c8
-rw-r--r--libappstream-glib/as-cleanup.h5
-rw-r--r--libappstream-glib/as-self-test.c8
3 files changed, 13 insertions, 8 deletions
diff --git a/libappstream-builder/asb-self-test.c b/libappstream-builder/asb-self-test.c
index 45e7092..7eb38ad 100644
--- a/libappstream-builder/asb-self-test.c
+++ b/libappstream-builder/asb-self-test.c
@@ -43,8 +43,7 @@
static gchar *
asb_test_get_filename (const gchar *filename)
{
- char full_tmp[PATH_MAX];
- gchar *tmp;
+ _cleanup_free_libc_ gchar *tmp = NULL;
_cleanup_free_ gchar *path = NULL;
/* try the source then the destdir */
@@ -53,10 +52,11 @@ asb_test_get_filename (const gchar *filename)
g_free (path);
path = g_build_filename (TESTDIRBUILD, filename, NULL);
}
- tmp = realpath (path, full_tmp);
+ /* glibc allocates a buffer */
+ tmp = realpath (path, NULL);
if (tmp == NULL)
return NULL;
- return g_strdup (full_tmp);
+ return g_strdup (tmp);
}
/**
diff --git a/libappstream-glib/as-cleanup.h b/libappstream-glib/as-cleanup.h
index 4554c44..33c5f99 100644
--- a/libappstream-glib/as-cleanup.h
+++ b/libappstream-glib/as-cleanup.h
@@ -29,6 +29,8 @@
#include "as-node.h"
#include "as-yaml.h"
+#include <stdlib.h>
+
G_BEGIN_DECLS
#define GS_DEFINE_CLEANUP_FUNCTION(Type, name, func) \
@@ -76,10 +78,13 @@ GS_DEFINE_CLEANUP_FUNCTION(char**, gs_local_strfreev, g_strfreev)
GS_DEFINE_CLEANUP_FUNCTION(GList*, gs_local_free_list, g_list_free)
GS_DEFINE_CLEANUP_FUNCTION(void*, gs_local_free, g_free)
+GS_DEFINE_CLEANUP_FUNCTION(void*, gs_local_free_libc, free)
+
#define _cleanup_date_time_unref_ __attribute__ ((cleanup(gs_local_date_time_unref)))
#define _cleanup_dir_close_ __attribute__ ((cleanup(gs_local_dir_close)))
#define _cleanup_timer_destroy_ __attribute__ ((cleanup(gs_local_destroy_timer)))
#define _cleanup_free_ __attribute__ ((cleanup(gs_local_free)))
+#define _cleanup_free_libc_ __attribute__ ((cleanup(gs_local_free_libc)))
#define _cleanup_checksum_free_ __attribute__ ((cleanup(gs_local_checksum_free)))
#define _cleanup_error_free_ __attribute__ ((cleanup(gs_local_free_error)))
#define _cleanup_list_free_ __attribute__ ((cleanup(gs_local_free_list)))
diff --git a/libappstream-glib/as-self-test.c b/libappstream-glib/as-self-test.c
index 83b583b..b28a927 100644
--- a/libappstream-glib/as-self-test.c
+++ b/libappstream-glib/as-self-test.c
@@ -76,15 +76,15 @@ as_test_compare_lines (const gchar *txt1, const gchar *txt2, GError **error)
static gchar *
as_test_get_filename (const gchar *filename)
{
- char full_tmp[PATH_MAX];
- gchar *tmp;
+ _cleanup_free_libc_ gchar *tmp = NULL;
_cleanup_free_ gchar *path = NULL;
path = g_build_filename (TESTDATADIR, filename, NULL);
- tmp = realpath (path, full_tmp);
+ /* glibc allocates a buffer */
+ tmp = realpath (path, NULL);
if (tmp == NULL)
return NULL;
- return g_strdup (full_tmp);
+ return g_strdup (tmp);
}
static GMainLoop *_test_loop = NULL;