public inbox for libffi-discuss@sourceware.org
 help / color / mirror / Atom feed
* return value buffer malloc()'ed vs alloca()'ed
@ 2013-10-08 17:14 Igor Bogomazov
  2013-10-08 17:30 ` Anthony Green
  2013-10-08 17:33 ` return value buffer malloc()'ed vs alloca()'ed Andrew Haley
  0 siblings, 2 replies; 9+ messages in thread
From: Igor Bogomazov @ 2013-10-08 17:14 UTC (permalink / raw)
  To: libffi-discuss

Hello,

I've been trying to investigate valgrind warnings for a while and found
an undocumented feature, please let me know if it is well-known.

What I did.

I modified a code given in «2.2 Simple Example» so that return value
(rc), originally declared as (int), became an (int *)malloc(sizeof(int))
so that it is resident in heap since that. Of cource, (&rc) replaced
with (rc) later in the code.

What I get.

valgrind complaints about «Invalid write of size 8» while «Address
0x55ec040 is 0 bytes inside a block of size 4 alloc'd», it is exactly
that allocated (rc) buffer.

Notes.

Allocating buffer for the return value using alloca() does the trick and
makes valgrind silent.

Further.

I looked at x86/unix64.S, it is exactly the line:
movq	%rax, (%rdi)
that causes the valgrind's warning (at .Lst_uint32)

That is my question: is it necessary to allocate a buffer for the return
value with alloca() and never with malloc()?

-- 
Sincerely yours,

Igor Bogomazov

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2013-11-16 11:24 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-10-08 17:14 return value buffer malloc()'ed vs alloca()'ed Igor Bogomazov
2013-10-08 17:30 ` Anthony Green
2013-10-08 17:36   ` Andrew Haley
2013-10-08 17:40     ` Anthony Green
2013-10-08 17:45       ` Andrew Haley
2013-10-09  5:09         ` Igor Bogomazov
2013-11-15 16:18       ` Broken tests in libffi testsuite Andrew Haley
2013-11-16 11:24         ` Alan Modra
2013-10-08 17:33 ` return value buffer malloc()'ed vs alloca()'ed Andrew Haley

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).