c - Valgrind: Invalid write of size 8 with a segfault -


so i'm working on long c code data analysis. when run it, segfaults. couldn't see obvious, ran through valgrind, following:

==7136== memcheck, memory error detector ==7136== copyright (c) 2002-2013, , gnu gpl'd, julian seward et al. ==7136== using valgrind-3.10.0.svn , libvex; rerun -h copyright info ==7136== command: ./exspec table.dat datafile_1 ==7136==  reading in table... obtaining rates... loading data file... ==7136== warning: set address range perms: large range [0x3a00e040,     0xaa00e040) (defined) ==7136== warning: set address range perms: large range [0xaa00f040, 0xdc11a5e0) (defined) ==7136== warning: set address range perms: large range [0x3a00e028, 0xaa00e058) (noaccess) converting units... computing fractions... calculating los , particle intersections... ==7136== warning: client switching stacks?  sp change: 0xffefffc60 -->    0xffb6c81a0 ==7136==          suppress, use: --max-stackframe=59996864 or greater ==7136== invalid write of size 8 ==7136==    @ 0x4040dd: get_particle_intersections (los.c:105) ==7136==    0x403e77: los (los.c:65) ==7136==    0x401236: main (main.c:73) ==7136==  address 0xffb6c8198 on thread 1's stack ==7136==  ==7136==  ==7136== process terminating default action of signal 11 (sigsegv) ==7136==  access not within mapped region @ address 0xffb6c8198 ==7136==    @ 0x4040dd: get_particle_intersections (los.c:105) ==7136==  if believe happened result of stack ==7136==  overflow in program's main thread (unlikely ==7136==  possible), can try increase size of ==7136==  main thread stack using --main-stacksize= flag. ==7136==  main thread stack size used in run 8388608. ==7136==  ==7136== process terminating default action of signal 11 (sigsegv) ==7136==  access not within mapped region @ address 0xffb6c8191 ==7136==    @ 0x4a256b0: _vgnu_freeres (in /usr/lib/valgrind/vgpreload_core-amd64-linux.so) ==7136==  if believe happened result of stack ==7136==  overflow in program's main thread (unlikely ==7136==  possible), can try increase size of ==7136==  main thread stack using --main-stacksize= flag. ==7136==  main thread stack size used in run 8388608. ==7136==  ==7136== heap summary: ==7136==     in use @ exit: 840,104,888 bytes in 4 blocks ==7136==   total heap usage: 1,447 allocs, 1,443 frees, 2,720,608,224 bytes allocated ==7136==  ==7136== leak summary: ==7136==    lost: 0 bytes in 0 blocks ==7136==    indirectly lost: 0 bytes in 0 blocks ==7136==      possibly lost: 0 bytes in 0 blocks ==7136==    still reachable: 840,104,888 bytes in 4 blocks ==7136==         suppressed: 0 bytes in 0 blocks ==7136== rerun --leak-check=full see details of leaked memory ==7136==  ==7136== counts of detected , suppressed errors, rerun with: -v ==7136== error summary: 1 errors 1 contexts (suppressed: 0 0) segmentation fault (core dumped) 

here's function says invalid write in (the first part of it, anyway, it's bit long):

void get_particle_intersections(void) {    int i;    int j;    int tot_overlap = 0;    int list[ngas];    float x;    float y;    float z;    float h;         for(i = 0; < npixels; i++)        {           pixels[i].noverlap = 0;            for(j = 0; j < ngas; j++)           {              x = (pixels[i].pos[0] - p[j].pos[0]) / cm_per_kpc;              y = (pixels[i].pos[1] - p[j].pos[1]) / cm_per_kpc;              z = (pixels[i].pos[2] - p[j].pos[2]) / cm_per_kpc;              h = p[j].hsml / cm_per_kpc;               if((pow(x, 2.0) + pow(y, 2.0) + pow(z, 2.0)) <= pow(h, 2.0))              {                  // stuff              }              // more stuff          }          // more stuff      } 

line 105 if(pow... line. both pixels , p globals memory allocated elsewhere with:

if(!(pixels = calloc(npixels, sizeof(pixel)))) {     printf("error, couldn't allocate memory pixels!\n");     exit(exit_failure); } 

and:

if(!(p = calloc(n_gas, sizeof(data)))) {     printf("error, couldn't allocate memory particles!\n");     exit(exit_failure); } 

they declared as:

pixel *pixels; data *p; 

the pos arrays within both pixels , p declared as:

float pos[3]; 

where pixel , data typedef structs. reason i'm asking because, if seg fault due invalid write, don't understand error, nothing being written @ line. led me believe actual error before line, whatever reason flagging @ line 105. anyways, said, code rather long, haven't posted of it, , guess it's possible error elsewhere, since that's program crashing, figured post section. also, crash occurring in middle of code, there several arrays have been allocated not yet freed @ point in program.

i've looked @ several of other questions related invalid writes on site, , seems related assignment of 1 data type another, or such thing. since valgrind telling me error @ if statement, though, figured i'd ask. thanks, , sorry rather long post!

edit: output gdb:

gnu gdb (ubuntu 7.7.1-0ubuntu5~14.04.2) 7.7.1 copyright (c) 2014 free software foundation, inc. license gplv3+: gnu gpl version 3 or later    <http://gnu.org/licenses/gpl.html> free software: free change , redistribute it. there no warranty, extent permitted law.  type "show copying" , "show warranty" details. gdb configured "x86_64-linux-gnu". type "show configuration" configuration details. bug reporting instructions, please see: <http://www.gnu.org/software/gdb/bugs/>. find gdb manual , other documentation resources online at: <http://www.gnu.org/software/gdb/documentation/>. help, type "help". type "apropos word" search commands related "word"... reading symbols ./exspec...done. (gdb) start table.dat datafile_1  temporary breakpoint 1 @ 0x40111c: file src/main.c, line 33. starting program: ./exspec table.dat datafile_1  temporary breakpoint 1, main (argc=3, argv=0x7fffffffde88) @   src/main.c:33 33     start = clock(); (gdb) b los.c:88 breakpoint 2 @ 0x403f02: file src/los.c, line 88. (gdb) c continuing. reading in table... obtaining rates... loading data file... converting units... computing fractions... calculating los , particle intersections...  breakpoint 2, get_particle_intersections () @ src/los.c:88 88     for(i = 0; < npixels; i++) (gdb) n 90        pixels[i].noverlap = 0; (gdb)  92        for(j = 0; j < ngas; j++) (gdb)  99           x = (pixels[i].pos[0] - p[j].pos[0]) / cm_per_kpc; (gdb)  100          y = (pixels[i].pos[1] - p[j].pos[1]) / cm_per_kpc; (gdb)  101          z = (pixels[i].pos[2] - p[j].pos[2]) / cm_per_kpc; (gdb)  102          h = p[j].hsml / cm_per_kpc; (gdb)  105          if((pow(x, 2.0) + pow(y, 2.0) + pow(z, 2.0)) <= pow(h, 2.0)) (gdb)   program received signal sigsegv, segmentation fault. 0x00000000004040dd in get_particle_intersections () @ src/los.c:105 105          if((pow(x, 2.0) + pow(y, 2.0) + pow(z, 2.0)) <= pow(h, 2.0)) 


Comments

Popular posts from this blog

twig - Using Twigbridge in a Laravel 5.1 Package -

jdbc - Not able to establish database connection in eclipse -

firemonkey - How do I make a beep sound in Android using Delphi and the API? -