0

I'm running a multi-threading program and I get every time errors like

malloc(): memory corruption

or Segmentation fault.

I decided to use valgrind to investigate which kind of problems my program shows. First of all I got the below output. Can someone help me to understand how to read the output messages?

 ==17413== Conditional jump or move depends on uninitialised value(s)
==17413==    at 0x47A2349: ns_name_ntop (ns_name.c:147)
==17413==    by 0x47A3271: ns_name_uncompress (ns_name.c:585)
==17413==    by 0x479B3EF: dn_expand (res_comp.c:93)
==17413==    by 0x479FD2B: __res_queriesmatch (res_send.c:327)
==17413==    by 0x47A0D19: __libc_res_nsend (res_send.c:1327)
==17413==    by 0x479DDC7: __libc_res_nquery (res_query.c:226)
==17413==    by 0x479E417: __libc_res_nquerydomain (res_query.c:582)
==17413==    by 0x479E8FB: __libc_res_nsearch (res_query.c:416)
==17413==    by 0x404B1D9: _nss_dns_gethostbyname3_r (dns-host.c:192)
==17413==    by 0x404B540: _nss_dns_gethostbyname_r (dns-host.c:273)
==17413==    by 0x42C53FA: gethostbyname_r@@GLIBC_2.1.2 (getXXbyYY_r.c:266)
==17413==    by 0x42C4B7B: gethostbyname (getXXbyYY.c:116)
==17413==  Uninitialised value was created by a stack allocation
==17413==    at 0x804ADA3: UDP_Server_Open(int&, unsigned short) (UDP_Server.cpp:16)
==17413== 
==17413== Use of uninitialised value of size 4
==17413==    at 0x47A2382: ns_name_ntop (ns_name.c:153)
==17413==    by 0x47A3271: ns_name_uncompress (ns_name.c:585)
==17413==    by 0x479B3EF: dn_expand (res_comp.c:93)
==17413==    by 0x479FD2B: __res_queriesmatch (res_send.c:327)
==17413==    by 0x47A0D19: __libc_res_nsend (res_send.c:1327)
==17413==    by 0x479DDC7: __libc_res_nquery (res_query.c:226)
==17413==    by 0x479E417: __libc_res_nquerydomain (res_query.c:582)
==17413==    by 0x479E8FB: __libc_res_nsearch (res_query.c:416)
==17413==    by 0x404B1D9: _nss_dns_gethostbyname3_r (dns-host.c:192)
==17413==    by 0x404B540: _nss_dns_gethostbyname_r (dns-host.c:273)
==17413==    by 0x42C53FA: gethostbyname_r@@GLIBC_2.1.2 (getXXbyYY_r.c:266)
==17413==    by 0x42C4B7B: gethostbyname (getXXbyYY.c:116)
==17413==  Uninitialised value was created by a stack allocation
==17413==    at 0x804ADA3: UDP_Server_Open(int&, unsigned short) (UDP_Server.cpp:16)

3 Answers 3

1

For the simplest approach, getting the information regarding the error(s) is to read an output like

 ==17413==    at 0x47A2349: ns_name_ntop (ns_name.c:147)

look at the

  • File Name (ns_name.c)
  • Line Number (147)
  • Function Name (ns_name_ntop)

and for the error message

Conditional jump or move depends on uninitialised value(s)

It basically says, you're using a conditional statement, like if, else if with an expression that contains a variable that can have uninitialized value. Sources of uninitialised data tend to be:

  1. Local variables in procedures which have not been initialised.
  2. The contents of heap blocks (allocated with malloc() or a similar function) before you write something there.

This way, you can start checking all the reported messages.

For more related information, you can check the on-line manual for memcheck tool in Valgrind.

0

This means you have an unitialized variable used in a statement and in a if.

Conditional jump or move depends on uninitialised value(s)

Means you do something like :

[...]
int i;
if (i == 0) ...
...

And

Use of uninitialised value of size 4

Means you probably have an unitialized pointer dereferenced:

struct *p;
p->toto = 0;
0
==17413==  Uninitialised value was created by a stack allocation
==17413==    at 0x804ADA3: UDP_Server_Open(int&, unsigned short) (UDP_Server.cpp:16)

This says that in UDP_Server.cpp at line 16 is a call to gethostbyname that is given an uninitialized value.

Not the answer you're looking for? Browse other questions tagged or ask your own question.