aboutsummaryrefslogtreecommitdiff
path: root/lib/mem.c
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org>2018-08-15 22:22:31 +0300
committerSergey Poznyakoff <gray@gnu.org>2018-08-15 22:22:31 +0300
commit7a40b7873bd666809183cdd952d6e2a8f1870981 (patch)
tree0ae71532dc78f597b717152b564d6681d1ad832a /lib/mem.c
parent988b8e27f5df26d7e9f6fd7984677873ca1c40cb (diff)
downloadpam-modules-7a40b7873bd666809183cdd952d6e2a8f1870981.tar.gz
pam-modules-7a40b7873bd666809183cdd952d6e2a8f1870981.tar.bz2
Major cleanup
* lib/graypam.h (gray_pam_init) (gray_raise,gray_malloc,gray_zalloc,gray_calloc) (gray_realloc,gray_strdup): Remove. (gray_slist_err,gray_slist_clrerr): New functions. (gray_slist_append,gray_slist_append_char): Return ssize_t. (gray_slist_coalesce): Likewise. (gray_slist_grow_backslash_num) (gray_slist_grow_backslash): Return int. (errno_to_pam): New function. (gray_set_transform_expr): Return int. * lib/mem.c (gray_raise,gray_malloc,gray_zalloc,gray_calloc) (gray_realloc,gray_strdup): Remove. (gray_2nrealloc): Rewrite. * lib/base64.c: Check return from gray_slist_append_char * lib/env.c: Check return values from gray_slist functions * lib/ldappass.c: Likewise. * lib/slist.c (gray_slist_bucket) <ec>: New member. (gray_slist_err,gray_slist_clrerr): New functions. (gray_slist_append,gray_slist_append_char): Return ssize_t. (gray_slist_coalesce): Likewise. (gray_slist_grow_backslash_num) (gray_slist_grow_backslash): Return int. * lib/transform.c: Use standard memory allocation functions. * pam_ldaphome/pam_ldaphome.c: Likewise. * pam_innetgr/pam_innetgr.c: Likewise. * pam_log/pam_log.c: Likewise. * pam_regex/pam_regex.c: Likewise. * pam_sql/pam_mysql.c: Likewise. * pam_sql/pam_pgsql.c: Likewise.
Diffstat (limited to 'lib/mem.c')
-rw-r--r--lib/mem.c81
1 files changed, 14 insertions, 67 deletions
diff --git a/lib/mem.c b/lib/mem.c
index fbe5f06..bcb0a89 100644
--- a/lib/mem.c
+++ b/lib/mem.c
@@ -18,48 +18,2 @@
-jmp_buf gray_pam_jmp;
-
-void
-gray_raise(const char *fmt, ...)
-{
- va_list ap;
- va_start(ap, fmt);
- _pam_vlog(LOG_ERR, fmt, ap);
- va_end(ap);
- longjmp(gray_pam_jmp, 1);
-}
-
-void *
-gray_malloc(size_t size)
-{
- void *p = malloc(size);
- if (!p)
- gray_raise("Not enough memory");
- return p;
-}
-
-void *
-gray_zalloc(size_t size)
-{
- void *p = malloc(size);
- if (!p)
- gray_raise("Not enough memory");
- memset(p, 0, size);
- return p;
-}
-
-void *
-gray_calloc(size_t count, size_t size)
-{
- return gray_zalloc(count * size);
-}
-
-void *
-gray_realloc(void *ptr, size_t size)
-{
- ptr = realloc(ptr, size);
- if (!ptr)
- gray_raise("Not enough memory");
- return ptr;
-}
-
void *
@@ -70,25 +24,18 @@ gray_2nrealloc(void *ptr, size_t *pcount, size_t elsiz)
if (!ptr) {
- if (!count)
- count = *pcount = 16;
- return gray_calloc(count, elsiz);
+ if (!count) {
+ count = 64 / elsiz;
+ count += !count;
+ }
+ } else {
+ if ((size_t)-1 / 2 / elsiz <= count) {
+ errno = ENOMEM;
+ return NULL;
+ }
+ count += (count + 1) / 2;
}
- if ((size_t)-1 / 2 / elsiz <= count)
- gray_raise("Not enough memory");
- count *= 2;
- *pcount = count;
- return gray_realloc(ptr, count * elsiz);
-}
-
-
-char *
-gray_strdup(const char *str)
-{
- char *p;
-
- if (!str)
- return NULL;
- p = gray_malloc(strlen(str) + 1);
- return strcpy(p, str);
+ ptr = realloc(ptr, count * elsiz);
+ if (ptr)
+ *pcount = count;
+ return ptr;
}
-

Return to:

Send suggestions and report system problems to the System administrator.