]> granicus.if.org Git - procps-ng/commitdiff
pmap: use correct types for memory allocation
authorSami Kerola <kerolasa@iki.fi>
Fri, 2 Nov 2012 17:50:50 +0000 (17:50 +0000)
committerCraig Small <csmall@enc.com.au>
Tue, 6 Nov 2012 11:22:11 +0000 (22:22 +1100)
Fixes error which did not happen always.  Changes of being affected by
the bug where greater the more there where pids defined as pmap argument.
The debian bug referral can almost certainly reproduce the problem,
especially when tried multiple times in row.

pmap: malloc.c:3096: sYSMALLOc: Assertion `(old_top == (((mbinptr)
(((char *) &((av)->bins[((1) - 1) * 2])) - __builtin_offsetof (struct
malloc_chunk, fd)))) && old_size == 0) || ((unsigned long) (old_size) >=
(unsigned long)((((__builtin_offsetof (struct malloc_chunk,
fd_nextsize))+((2 * (sizeof(size_t))) - 1)) & ~((2 * (sizeof(size_t))) -
1))) && ((old_top)->size & 0x1) && ((unsigned long)old_end & pagemask) ==
0)' failed.

Reported-by: lee <lee@yun.yagibdah.de>
Bug-Debian: http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=688180
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
pmap.c
proc/alloc.c
proc/alloc.h

diff --git a/pmap.c b/pmap.c
index 4fb7a61c9bcbe3557f7485940d06a3ee1bf4f9c5..742fcea9a232466a0850dd7463f2d6c0c1836147 100644 (file)
--- a/pmap.c
+++ b/pmap.c
@@ -661,7 +661,7 @@ int main(int argc, char **argv)
            x_option && (d_option || X_option))
                xerrx(EXIT_FAILURE, _("options -d, -x, -X are mutually exclusive"));
 
-       pidlist = xmalloc(sizeof(unsigned) * argc);
+       pidlist = xmalloc(sizeof(unsigned long) * argc);
 
        while (*argv) {
                char *walk = *argv++;
index 671d75237bb72be509e36f6c86e4658c775f62aa..94af47f7231406839308d79c8943b44c413a34a2 100644 (file)
@@ -50,14 +50,14 @@ void *xcalloc(unsigned int size) {
     return p;
 }
 
-void *xmalloc(unsigned int size) {
+void *xmalloc(size_t size) {
     void *p;
 
     if (size == 0)
         ++size;
     p = malloc(size);
     if (!p) {
-        xalloc_err_handler("%s failed to allocate %u bytes of memory", __func__, size);
+       xalloc_err_handler("%s failed to allocate %zu bytes of memory", __func__, size);
         exit(EXIT_FAILURE);
     }
     return(p);
index 82b53592a785e95136ded39bff9b9f8f5b77853d..19c91d78b76b6f8464e57fa8a1d8d30838b71344 100644 (file)
@@ -9,7 +9,7 @@ EXTERN_C_BEGIN
 extern message_fn xalloc_err_handler;
 
 extern void *xcalloc(unsigned int size) MALLOC;
-extern void *xmalloc(unsigned int size) MALLOC;
+extern void *xmalloc(size_t size) MALLOC;
 extern void *xrealloc(void *oldp, unsigned int size) MALLOC;
 extern char *xstrdup(const char *str) MALLOC;