public inbox for glibc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug stdio/18375] New: Syscall param write(buf) points to uninitialised byte(s) (valgrind reports)
@ 2015-05-05  0:54 eugeniofonseca14 at gmail dot com
  2015-05-05  0:59 ` [Bug stdio/18375] " eugeniofonseca14 at gmail dot com
  2015-05-05 17:43 ` schwab@linux-m68k.org
  0 siblings, 2 replies; 3+ messages in thread
From: eugeniofonseca14 at gmail dot com @ 2015-05-05  0:54 UTC (permalink / raw)
  To: glibc-bugs

https://sourceware.org/bugzilla/show_bug.cgi?id=18375

            Bug ID: 18375
           Summary: Syscall param write(buf) points to uninitialised
                    byte(s) (valgrind reports)
           Product: glibc
           Version: unspecified
            Status: NEW
          Severity: normal
          Priority: P2
         Component: stdio
          Assignee: unassigned at sourceware dot org
          Reporter: eugeniofonseca14 at gmail dot com
  Target Milestone: ---

Created attachment 8300
  --> https://sourceware.org/bugzilla/attachment.cgi?id=8300&action=edit
Code that reproduces the error.

Hello all,

The code I'm sending generates a valid output file, but valgrind accuses
fclose() of violating memory, when flushing the file buffer to disk. fcloses
does what it is supposed to do, despite the memory access error.

#include<stdio.h>
#include<stdlib.h>

typedef struct{
    int x;
    int y;
    double distanceFromBase;
    unsigned int tanks;
    long long int ackIndex;
} TankAttack;


int main(){
    FILE* arq;
    TankAttack* p = (TankAttack*)malloc(sizeof(TankAttack));

    arq = fopen("0","wb");

    p->x = 10;
    p->y = 10;
    p->distanceFromBase = 10.0;
    p->tanks = 10;
    p->ackIndex = 10;

    fwrite(p,sizeof(TankAttack),1,arq);

    fclose(arq);
    free(p);
    return 0;
}

==6143== Syscall param write(buf) points to uninitialised byte(s)
==6143==    at 0x4F2F4E0: __write_nocancel (syscall-template.S:81)
==6143==    by 0x4EB1BFE: _IO_file_write@@GLIBC_2.2.5 (fileops.c:1251)
==6143==    by 0x4EB30E8: new_do_write (fileops.c:506)
==6143==    by 0x4EB30E8: _IO_do_write@@GLIBC_2.2.5 (fileops.c:482)
==6143==    by 0x4EB296F: _IO_file_close_it@@GLIBC_2.2.5 (fileops.c:164)
==6143==    by 0x4EA6851: fclose@@GLIBC_2.2.5 (iofclose.c:59)
==6143==    by 0x4006E5: main (in /home/eugenio/AEDS/WW2/out)
==6143==  Address 0x4026014 is not stack'd, malloc'd or (recently) free'd
==6143== 
==6143== 
==6143== HEAP SUMMARY:
==6143==     in use at exit: 0 bytes in 0 blocks
==6143==   total heap usage: 2 allocs, 2 frees, 584 bytes allocated
==6143== 
==6143== All heap blocks were freed -- no leaks are possible

-- 
You are receiving this mail because:
You are on the CC list for the bug.


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

end of thread, other threads:[~2015-05-05 17:43 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-05-05  0:54 [Bug stdio/18375] New: Syscall param write(buf) points to uninitialised byte(s) (valgrind reports) eugeniofonseca14 at gmail dot com
2015-05-05  0:59 ` [Bug stdio/18375] " eugeniofonseca14 at gmail dot com
2015-05-05 17:43 ` schwab@linux-m68k.org

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).