malloc_g

Hi,

Please,
anybody , say me what is my wrong?

I compile tests from
http://qdn.qnx.com/support/docs/neutrino/prog/hat.html
such as

// file xxx.c
#include<malloc_g/malloc.h>
void f(){
char *p;
mallopt(MALLOC_CKACCESS, M_HANDLE_ABORT);
p = malloc(strlen(“hello”));
strcpy(p, “hello, there!”);
}

main(){
f1();
}

qcc -o xxx xxx.c -Bdynamic -lmalloc_g

it does not work!
Q: WHY?


next

// file xxx.c
#include<malloc_g/malloc.h>
main(){
void *p;
for(i=0;i<1000;i++) p=malloc(1000);
malloc_dump(1);
}

it was compiled OK as follows:
qcc -o xxx xxx.c -Bdynamic -lmalloc_g
but during execution it said (like that):
unresolved symbol “malloc_dump”

Q: what’s the matter???


next

if I do
{
for(i=0;i<1000;i++) p=malloc(1000);
h=dlopen("/usr/lib/malloc_g.so",…)
f=dlsym(h, “malloc_dump”);
f(1);
}
it outputs empty list!
Q: what’s the matter???


Thanks a much!
vasa

vasa a écrit :

Hi,

Please,
anybody , say me what is my wrong?

I compile tests from
http://qdn.qnx.com/support/docs/neutrino/prog/hat.html
such as

// file xxx.c
#include<malloc_g/malloc.h
void f(){
char *p;
mallopt(MALLOC_CKACCESS, M_HANDLE_ABORT);
p = malloc(strlen(“hello”));
strcpy(p, “hello, there!”);
}

main(){
f1();
}

qcc -o xxx xxx.c -Bdynamic -lmalloc_g

it does not work!
Q: WHY?

When a process is created, an amount of memory is allocated for it. I
don’t really know how much, it could depend on the memory needed at the
beginning but it’s a multiple of 4 kb. it’s called the heap.
When you call malloc(), there is 2 solutions. If there is enough memory
in the heap, no memory is requested to the os. The local table is
updated. If there is not enough memory, the os will give you at least 4
kb. In fact, it’s defined by the MMU.
If, after a malloc(), you write past of bounds, the result will again
depend on several conditions.
If you write out of the heap bounds, the MMU will detect the fault and
the os will kill your process.
If you write in a yet allocated block which belongs to your heap, will
cause problem when you will free the corrupted block.
If you write in an unallocated block, you will have a memory fault on a
subsequent allocation request.
So, in your example, there is no problem! Maybe if you call malloc()
after strcpy().


next

// file xxx.c
#include<malloc_g/malloc.h
main(){
void *p;
for(i=0;i<1000;i++) p=malloc(1000);
malloc_dump(1);
}

it was compiled OK as follows:
qcc -o xxx xxx.c -Bdynamic -lmalloc_g
but during execution it said (like that):
unresolved symbol “malloc_dump”

Q: what’s the matter???

As far as I remember, you need the ‘-DNDEBUG’ and ‘-DMALLOC_DEBUG’
options to be able to use these functions.


next

if I do
{
for(i=0;i<1000;i++) p=malloc(1000);
h=dlopen("/usr/lib/malloc_g.so",…)
f=dlsym(h, “malloc_dump”);
f(1);
}
it outputs empty list!
Q: what’s the matter???

Thanks a much!
vasa

vasa <vv40in@rambler.ru> wrote:
: Hi,

: Please,
: anybody , say me what is my wrong?

: I compile tests from
: http://qdn.qnx.com/support/docs/neutrino/prog/hat.html
: such as

: // file xxx.c
: #include<malloc_g/malloc.h>
: void f(){
: char *p;
: mallopt(MALLOC_CKACCESS, M_HANDLE_ABORT);
: p = malloc(strlen(“hello”));
: strcpy(p, “hello, there!”);
: }

: main(){
: f1();
: }

: qcc -o xxx xxx.c -Bdynamic -lmalloc_g

: it does not work!
: Q: WHY?

For some reason we seem to have different version
of libmalloc_g lying around. BTW the other poster
did give some valuable info.

Try :

qcc -g -o x x.c -lmalloc_g -I /usr/include/malloc_g

LD_LIBRARY_PATH=/usr/lib/malloc_g ./x

MALLOC Warning from strcpy() (called from instruction preceding 0x08048541):
Pointer within malloc region, but outside of malloc data bounds
This error is probably associated with the following allocation:

A call to malloc for 5 bytes in an unknown file near 8048528.
This was the 15th call to malloc.

@ [0x0804849C]
@ (main+0x0000000B)[0x08048553]
@ [0x08048541]
@ libmalloc.so.2:(strcpy+0x00000023)[0xB035D133]
@ libmalloc.so.2:(DBstrcpy+0x000000CE)[0xB035D206]
@ libmalloc.so.2:(malloc_check_data+0x00000094)[0xB03575B0]

: -----------------
: next

: // file xxx.c
: #include<malloc_g/malloc.h>
: main(){
: void *p;
: for(i=0;i<1000;i++) p=malloc(1000);
: malloc_dump(1);
: }

: it was compiled OK as follows:
: qcc -o xxx xxx.c -Bdynamic -lmalloc_g
: but during execution it said (like that):
: unresolved symbol “malloc_dump”

: Q: what’s the matter???

Yes. You are using the wrong malloc_g shared lib.

: -----------------------
: next

: if I do
: {
: for(i=0;i<1000;i++) p=malloc(1000);
: h=dlopen("/usr/lib/malloc_g.so",…)
: f=dlsym(h, “malloc_dump”);
: f(1);
: }
: it outputs empty list!
: Q: what’s the matter???


: Thanks a much!
: vasa

What is a PR, to whom i am sending it to?

Rejean Senecal <rsenecal@oerlikon.ca> wrote:
: What is a PR

Problem Report.

: to whom i am sending it to?

Usually you must have a valid account, but
I think you can do it via the web page:

http://qdn.qnx.com

[developers forum]

  • Problem Reporting <— this link.