c++ - Valgrind says about "Invalid write" in fclose() -


i created stream using fmemopen(). closing fclose() , freeing buffer after reading. valgrind reports problem @ fclose() line:

==9323== invalid write of size 8 ==9323==    @ 0x52cae52: _io_mem_finish (memstream.c:139) ==9323==    0x52c6a3e: fclose@@glibc_2.2.5 (iofclose.c:63) ==9323==    0x400cb6: main (main.cpp:80) ==9323==  address 0xffefffa80 below stack ptr.  suppress,  use: --workaround-gcc296-bugs=yes 

what's happening? maybe fclose() cannot close memory stream? or maybe valgrind worries without reason , can ignore that?

as haven't posted code, following pure speculation. you're writing more output stream promised when opened it. did account final nul (if didn't open "b")?

did read following in manual page?

when stream has been opened writing flushed (fflush(3)) or closed (fclose(3)), null byte written @ end of buffer if there space. caller should ensure byte available in buffer (and size counts byte) allow this.

attempts write more size bytes buffer result in error. (by default, such errors visible when stdio buffer flushed. disabling buffering setbuf(fp, null) may useful detect errors @ time of output operation. alternatively, caller can explicitly set buf stdio stream buffer, @ same time informing stdio of buffer's size, using setbuffer(fp, buf, size).)

following latter advice should reveal write exceeding capacity.


Comments

Popular posts from this blog

Magento/PHP - Get phones on all members in a customer group -

php - .htaccess mod_rewrite for dynamic url which has domain names -

Website Login Issue developed in magento -