aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/gpg-error.def.in3
-rw-r--r--src/gpg-error.h.in12
-rw-r--r--src/gpg-error.vers3
-rw-r--r--src/gpgrt-int.h1
-rw-r--r--src/init.c21
-rw-r--r--src/visibility.c18
-rw-r--r--src/visibility.h6
7 files changed, 63 insertions, 1 deletions
diff --git a/src/gpg-error.def.in b/src/gpg-error.def.in
index b718c7a..a9cfed9 100644
--- a/src/gpg-error.def.in
+++ b/src/gpg-error.def.in
@@ -183,5 +183,8 @@ EXPORTS
gpgrt_log_flush @139
_gpgrt_log_assert @140
+ gpgrt_realloc @141
+ gpgrt_malloc @142
+ gpgrt_calloc @143
;; end of file with public symbols for Windows.
diff --git a/src/gpg-error.h.in b/src/gpg-error.h.in
index 2d515d5..3e7d59b 100644
--- a/src/gpg-error.h.in
+++ b/src/gpg-error.h.in
@@ -434,6 +434,17 @@ gpg_error_from_syserror (void)
/*
+ * Malloc and friends
+ */
+
+void *gpgrt_realloc (void *a, size_t n);
+void *gpgrt_malloc (size_t n);
+void *gpgrt_calloc (size_t n, size_t m);
+void gpgrt_free (void *a);
+
+
+
+/*
* Lock functions.
*/
@@ -723,7 +734,6 @@ int gpgrt_fputs_unlocked (const char *_GPGRT__RESTRICT s,
@api_ssize_t@ gpgrt_read_line (gpgrt_stream_t stream,
char **addr_of_buffer, size_t *length_of_buffer,
size_t *max_length);
-void gpgrt_free (void *a);
int gpgrt_fprintf (gpgrt_stream_t _GPGRT__RESTRICT stream,
const char *_GPGRT__RESTRICT format, ...)
diff --git a/src/gpg-error.vers b/src/gpg-error.vers
index 6cce976..6276758 100644
--- a/src/gpg-error.vers
+++ b/src/gpg-error.vers
@@ -157,6 +157,9 @@ GPG_ERROR_1.0 {
gpgrt_log_flush;
_gpgrt_log_assert;
+ gpgrt_realloc;
+ gpgrt_malloc;
+ gpgrt_calloc;
local:
*;
diff --git a/src/gpgrt-int.h b/src/gpgrt-int.h
index f6f8d0e..4db330f 100644
--- a/src/gpgrt-int.h
+++ b/src/gpgrt-int.h
@@ -104,6 +104,7 @@ void _gpgrt_set_alloc_func (void *(*f)(void *a, size_t n));
void *_gpgrt_realloc (void *a, size_t n);
void *_gpgrt_malloc (size_t n);
void _gpgrt_free (void *a);
+void *_gpgrt_calloc (size_t n, size_t m);
const char *_gpg_error_check_version (const char *req_version);
diff --git a/src/init.c b/src/init.c
index b01e089..0154091 100644
--- a/src/init.c
+++ b/src/init.c
@@ -194,6 +194,27 @@ _gpgrt_malloc (size_t n)
}
+void *
+_gpgrt_calloc (size_t n, size_t m)
+{
+ size_t bytes;
+ void *p;
+
+ bytes = n * m; /* size_t is unsigned so the behavior on overflow is
+ defined. */
+ if (m && bytes / m != n)
+ {
+ _gpg_err_set_errno (ENOMEM);
+ return NULL;
+ }
+
+ p = _gpgrt_realloc (NULL, bytes);
+ if (p)
+ memset (p, 0, bytes);
+ return p;
+}
+
+
/* The free to be used for data returned by the public API. */
void
_gpgrt_free (void *a)
diff --git a/src/visibility.c b/src/visibility.c
index 569c3e6..6172769 100644
--- a/src/visibility.c
+++ b/src/visibility.c
@@ -504,6 +504,24 @@ gpgrt_read_line (estream_t stream,
max_length);
}
+void *
+gpgrt_realloc (void *a, size_t n)
+{
+ return _gpgrt_realloc (a, n);
+}
+
+void *
+gpgrt_malloc (size_t n)
+{
+ return _gpgrt_malloc (n);
+}
+
+void *
+gpgrt_calloc (size_t n, size_t m)
+{
+ return _gpgrt_calloc (n, m);
+}
+
void
gpgrt_free (void *a)
{
diff --git a/src/visibility.h b/src/visibility.h
index dca3019..596a6f2 100644
--- a/src/visibility.h
+++ b/src/visibility.h
@@ -118,6 +118,9 @@ MARK_VISIBLE (gpgrt_fputs)
MARK_VISIBLE (gpgrt_fputs_unlocked)
MARK_VISIBLE (gpgrt_getline)
MARK_VISIBLE (gpgrt_read_line)
+MARK_VISIBLE (gpgrt_realloc)
+MARK_VISIBLE (gpgrt_malloc)
+MARK_VISIBLE (gpgrt_calloc)
MARK_VISIBLE (gpgrt_free)
MARK_VISIBLE (gpgrt_fprintf)
MARK_VISIBLE (gpgrt_fprintf_unlocked)
@@ -257,6 +260,9 @@ MARK_VISIBLE (_gpgrt_log_assert)
#define gpgrt_fputs_unlocked _gpgrt_USE_UNDERSCORED_FUNCTION
#define gpgrt_getline _gpgrt_USE_UNDERSCORED_FUNCTION
#define gpgrt_read_line _gpgrt_USE_UNDERSCORED_FUNCTION
+#define gpgrt_realloc _gpgrt_USE_UNDERSCORED_FUNCTION
+#define gpgrt_malloc _gpgrt_USE_UNDERSCORED_FUNCTION
+#define gpgrt_calloc _gpgrt_USE_UNDERSCORED_FUNCTION
#define gpgrt_free _gpgrt_USE_UNDERSCORED_FUNCTION
#define gpgrt_fprintf _gpgrt_USE_UNDERSCORED_FUNCTION
#define gpgrt_fprintf_unlocked _gpgrt_USE_UNDERSCORED_FUNCTION