It's not obvious to me..... I don't know what the problem with memmove =
is
since the man page says it should handle overlaps and at this stage it
is a simple malloc of two spaces and a memmove between them.
Any help would be greatly appreciated.
[----------------------- source listing ------------------------------]
#include <unistd.h>
#include <string.h>
#include <malloc.h>
#define ADD_ON_SIZE 10
#define INITIAL_SIZE 11
size_t size =3D INITIAL_SIZE;
int main(int argc, char **argv)
{
int index_ctr =3D 0;
void * ptr1 =3D (void *) NULL;
void * ptr2 =3D (void *) NULL;
ptr1 =3D malloc(size);
size +=3D ADD_ON_SIZE;
ptr2 =3D malloc(size);
ptr2 =3D memmove(ptr2,ptr1,size);
free (ptr2);
free (ptr1);
return 0;
}
$ valgrind ./t_malloc=20
=3D=3D5879=3D=3D Memcheck, a.k.a. Valgrind, a memory error detector for =
x86-linux.
=3D=3D5879=3D=3D Copyright (C) 2002-2003, and GNU GPL'd, by Julian =
Seward.
=3D=3D5879=3D=3D Using valgrind-20030725, a program supervision =
framework for x86-linux.
=3D=3D5879=3D=3D Copyright (C) 2000-2003, and GNU GPL'd, by Julian =
Seward.
=3D=3D5879=3D=3D Estimated CPU clock rate is 1398 MHz
=3D=3D5879=3D=3D For more details, rerun with: -v
=3D=3D5879=3D=3D=20
=3D=3D5879=3D=3D Invalid read of size 1
=3D=3D5879=3D=3D at 0x402CDE2A: memmove =
(../sysdeps/generic/memmove.c:79)
=3D=3D5879=3D=3D by 0x8048535: main (in =
/share/systems/views/garedman/garedman_linux_ehs/.s/00053/80003c634015a64=
et_malloc)
=3D=3D5879=3D=3D by 0x40261686: __libc_start_main =
(../sysdeps/generic/libc-start.c:129)
=3D=3D5879=3D=3D by 0x80483F0: (within =
/share/systems/views/garedman/garedman_linux_ehs/.s/00053/80003c634015a64=
et_malloc)
=3D=3D5879=3D=3D Address 0x4146002F is 0 bytes after a block of size =
11 alloc'd
=3D=3D5879=3D=3D at 0x4002B944: malloc (vg_replace_malloc.c:153)
=3D=3D5879=3D=3D by 0x80484F8: main (in =
/share/systems/views/garedman/garedman_linux_ehs/.s/00053/80003c634015a64=
et_malloc)
=3D=3D5879=3D=3D by 0x40261686: __libc_start_main =
(../sysdeps/generic/libc-start.c:129)
=3D=3D5879=3D=3D by 0x80483F0: (within =
/share/systems/views/garedman/garedman_linux_ehs/.s/00053/80003c634015a64=
et_malloc)
=3D=3D5879=3D=3D=20
=3D=3D5879=3D=3D ERROR SUMMARY: 10 errors from 1 contexts (suppressed: 0 =
from 0)
=3D=3D5879=3D=3D malloc/free: in use at exit: 0 bytes in 0 blocks.
=3D=3D5879=3D=3D malloc/free: 2 allocs, 2 frees, 32 bytes allocated.
=3D=3D5879=3D=3D For a detailed leak analysis, rerun with: =
--leak-check=3Dyes
=3D=3D5879=3D=3D For counts of detected errors, rerun with: -v
------ gory details run.....
$ valgrind -v ./t_malloc
=3D=3D5915=3D=3D Memcheck, a.k.a. Valgrind, a memory error detector for =
x86-linux.
=3D=3D5915=3D=3D Copyright (C) 2002-2003, and GNU GPL'd, by Julian =
Seward.
=3D=3D5915=3D=3D Using valgrind-20030725, a program supervision =
framework for x86-linux.
=3D=3D5915=3D=3D Copyright (C) 2000-2003, and GNU GPL'd, by Julian =
Seward.
=3D=3D5915=3D=3D Startup, with flags:
=3D=3D5915=3D=3D =
--suppressions=3D/usr/local/lib/valgrind/default.supp
=3D=3D5915=3D=3D -v
=3D=3D5915=3D=3D Reading syms from =
/share/systems/views/garedman/garedman_linux_ehs/.s/00053/80003c634015a64=
et_malloc
=3D=3D5915=3D=3D Reading syms from /lib/ld-2.2.4.so
=3D=3D5915=3D=3D Reading syms from =
/usr/local/lib/valgrind/vgskin_memcheck.so
=3D=3D5915=3D=3D Reading syms from /usr/local/lib/valgrind/valgrind.so
=3D=3D5915=3D=3D Reading syms from /lib/i686/libc-2.2.4.so
=3D=3D5915=3D=3D Reading suppressions file: =
/usr/local/lib/valgrind/default.supp
=3D=3D5915=3D=3D Estimated CPU clock rate is 1399 MHz
=3D=3D5915=3D=3D=20
=3D=3D5915=3D=3D Invalid read of size 1
=3D=3D5915=3D=3D at 0x402CDE2A: memmove =
(../sysdeps/generic/memmove.c:79)
=3D=3D5915=3D=3D by 0x8048535: main (in =
/share/systems/views/garedman/garedman_linux_ehs/.s/00053/80003c634015a64=
et_malloc)
=3D=3D5915=3D=3D by 0x40261686: __libc_start_main =
(../sysdeps/generic/libc-start.c:129)
=3D=3D5915=3D=3D by 0x80483F0: (within =
/share/systems/views/garedman/garedman_linux_ehs/.s/00053/80003c634015a64=
et_malloc)
=3D=3D5915=3D=3D Address 0x4146002F is 0 bytes after a block of size =
11 alloc'd
=3D=3D5915=3D=3D at 0x4002B944: malloc (vg_replace_malloc.c:153)
=3D=3D5915=3D=3D by 0x80484F8: main (in =
/share/systems/views/garedman/garedman_linux_ehs/.s/00053/80003c634015a64=
et_malloc)
=3D=3D5915=3D=3D by 0x40261686: __libc_start_main =
(../sysdeps/generic/libc-start.c:129)
=3D=3D5915=3D=3D by 0x80483F0: (within =
/share/systems/views/garedman/garedman_linux_ehs/.s/00053/80003c634015a64=
et_malloc)
=3D=3D5915=3D=3D=20
=3D=3D5915=3D=3D ERROR SUMMARY: 10 errors from 1 contexts (suppressed: 0 =
from 0)
=3D=3D5915=3D=3D=20
=3D=3D5915=3D=3D 10 errors in context 1 of 1:
=3D=3D5915=3D=3D Invalid read of size 1
=3D=3D5915=3D=3D at 0x402CDE2A: memmove =
(../sysdeps/generic/memmove.c:79)
=3D=3D5915=3D=3D by 0x8048535: main (in =
/share/systems/views/garedman/garedman_linux_ehs/.s/00053/80003c634015a64=
et_malloc)
=3D=3D5915=3D=3D by 0x40261686: __libc_start_main =
(../sysdeps/generic/libc-start.c:129)
=3D=3D5915=3D=3D by 0x80483F0: (within =
/share/systems/views/garedman/garedman_linux_ehs/.s/00053/80003c634015a64=
et_malloc)
=3D=3D5915=3D=3D Address 0x4146002F is 0 bytes after a block of size =
11 alloc'd
=3D=3D5915=3D=3D at 0x4002B944: malloc (vg_replace_malloc.c:153)
=3D=3D5915=3D=3D by 0x80484F8: main (in =
/share/systems/views/garedman/garedman_linux_ehs/.s/00053/80003c634015a64=
et_malloc)
=3D=3D5915=3D=3D by 0x40261686: __libc_start_main =
(../sysdeps/generic/libc-start.c:129)
=3D=3D5915=3D=3D by 0x80483F0: (within =
/share/systems/views/garedman/garedman_linux_ehs/.s/00053/80003c634015a64=
et_malloc)
=3D=3D5915=3D=3D IN SUMMARY: 10 errors from 1 contexts (suppressed: 0 =
from 0)
=3D=3D5915=3D=3D=20
=3D=3D5915=3D=3D malloc/free: in use at exit: 0 bytes in 0 blocks.
=3D=3D5915=3D=3D malloc/free: 2 allocs, 2 frees, 32 bytes allocated.
=3D=3D5915=3D=3D=20
--5915-- TT/TC: 0 tc sectors discarded.
--5915-- 290 chainings, 0 unchainings.
--5915-- translate: new 736 (9572 -> 143181; ratio 149:10)
--5915-- discard 0 (0 -> 0; ratio 0:10).
--5915-- dispatch: 0 jumps (bb entries), of which 1032 (103200%) were =
unchained.
--5915-- 2/743 major/minor sched events. 736 tt_fast misses.
--5915-- reg-alloc: 60 t-req-spill, 27269+359 orig+spill uis, 3363 =
total-reg-r.
--5915-- sanity: 3 cheap, 1 expensive checks.
--5915-- ccalls: 3278 C calls, 62% saves+restores avoided (12128 =
bytes)
--5915-- 4073 args, avg 0.89 setup instrs each (820 bytes)
--5915-- 0% clear the stack (9834 bytes)
--5915-- 1191 retvals, 32% of reg-reg movs avoided (750 =
bytes)
Mark S. Watts
Huntsville Operations Support Center (HOSC)
CSC/NASA
Huntsville, AL
256-544-6165
|