summaryrefslogtreecommitdiff
path: root/lib/javaversion.c
diff options
context:
space:
mode:
authorBruno Haible <bruno@clisp.org>2017-05-16 20:57:23 +0200
committerBruno Haible <bruno@clisp.org>2017-05-16 20:57:23 +0200
commit3a285f29fbdb5761174bf22b6390932bfab03fad (patch)
treec8dcecaa4a443109afe62186adaef6f1699b98bc /lib/javaversion.c
parent88fdf7f84a0b5965eb23a9ea8a24975cf4a06e1f (diff)
downloadgnulib-3a285f29fbdb5761174bf22b6390932bfab03fad.tar.gz
relocate: Make it easier to reclaim allocated memory.
* lib/relocatable.h (relocate2): New declaration/macro. * lib/relocatable.c (relocate2): New function. * doc/relocatable-maint.texi (Supporting Relocation): Mention the relocate2 function. * lib/localcharset.c (relocate2): Define fallback. (get_charset_aliases): Invoke relocate2 instead of relocate. Free the allocated memory. * lib/javaversion.c (relocate2): Define fallback. (javaexec_version): Invoke relocate2 instead of relocate. Free the allocated memory.
Diffstat (limited to 'lib/javaversion.c')
-rw-r--r--lib/javaversion.c6
1 files changed, 5 insertions, 1 deletions
diff --git a/lib/javaversion.c b/lib/javaversion.c
index 817ba0c7e3..f2331aaa6f 100644
--- a/lib/javaversion.c
+++ b/lib/javaversion.c
@@ -23,11 +23,13 @@
#include <errno.h>
#include <stdbool.h>
#include <stdio.h>
+#include <stdlib.h>
#if ENABLE_RELOCATABLE
# include "relocatable.h"
#else
# define relocate(pathname) (pathname)
+# define relocate2(pathname,allocatedp) (*(allocatedp) = NULL, (pathname))
#endif
#include "javaexec.h"
@@ -106,7 +108,8 @@ char *
javaexec_version (void)
{
const char *class_name = "javaversion";
- const char *pkgdatadir = relocate (PKGDATADIR);
+ char *malloc_pkgdatadir;
+ const char *pkgdatadir = relocate2 (PKGDATADIR, &malloc_pkgdatadir);
const char *args[1];
struct locals locals;
@@ -115,5 +118,6 @@ javaexec_version (void)
execute_java_class (class_name, &pkgdatadir, 1, true, NULL, args,
false, false, execute_and_read_line, &locals);
+ free (malloc_pkgdatadir);
return locals.line;
}