[zeromq-dev] Invalid argument (mutex.hpp:98)

Azamat Shakhimardanov shakhimardanov at yahoo.com
Tue May 10 17:25:40 CEST 2011


Hi, 
I was testing the following code and got this error:

Code:

while(j < 10)
{
 zmq_msg_t msg;
 gettimeofday(&(m.timestamp), NULL); 
 zmq_msg_init_data(&msg, &m, sizeof m, NULL, NULL);
 zmq_send(publisher, &msg, 0);
 zmq_msg_close(&msg);
 j=j+1;
 usleep(HERTZ_100);
 }
  zmq_close(publisher);
  zmq_term(context);
 return 0;

Error:
Here "m" is struct of char array and timeval; statically allocated.
After sending required number of messages application quits with 

"Invalid argument (mutex.hpp:98)
Aborted"

Could not find any reasonable response to the problem, though it was briefly mentioned in IRC chat. I am using TCP socket, zmq_close returns OK, zmq_term does not return at all. When zmq_term is completely removed application finishes OK. With 2.0.9 it was just giving SIGSEGV, but with newer version (2.1.6) it is more verbose but Valgrind still says that application received SIGSEGV.

Setup:
- zmq-2.1.6 
- debian lenny with 2.6.32-5-686 kernel, 
- gcc 4.4.5-8


Valgrind:
Valgrind output says that there is invalid memory read, no leaks

==466== Invalid read of size 4
==466==    at 0x4378E57: pthread_mutex_lock (pthread_mutex_lock.c:61)
==466==    by 0x42B3FD5: pthread_mutex_lock (forward.c:182)
==466==    by 0x40300F4: zmq::ctx_t::terminate() (mutex.hpp:96)
==466==    by 0x4051778: zmq_term (zmq.cpp:292)
==466==    by 0x8048A15: main (testPublisherExperiment.c:76)
==466==  Address 0x469251c is 212 bytes inside a block of size 352 free'd
==466==    at 0x4023B6A: free (vg_replace_malloc.c:366)
==466==    by 0x4236739: fclose@@GLIBC_2.1 (iofclose.c:88)
==466==    by 0x432B0D0: pgm_time_init (time.c:342)
==466==    by 0x434B0D0: pgm_init (engine.c:164)
==466==    by 0x4051832: zmq_init (zmq.cpp:247)
==466==    by 0x8048829: main (testPublisherExperiment.c:32)
==466== 


Thanks in advance




More information about the zeromq-dev mailing list