Valgrind Error "Invalid write of size 4" C -


i'm programming in c, , when use valgrind check memory errors, next error has shown:

==9756== invalid write of size 4 ==9756==    @ 0x40164d: main (flowtracker.c:294) ==9756==  address 0x24 not stack'd, malloc'd or (recently) free'd 

the line 294 of flowtracker.c next:

tabla_hash[clave_hash]->contador++; 

and declaration of tabla_hash is:

#define tamanho_tabla 1048576  typedef struct{      int tiempo_ini;     int tiempo_ult;     uint8_t quintupla[13];     int num_bytes;     int num_syn;     int num_ack;     int contador;     double pack_s;     double bits_s; } flujoip;  flujoip *tabla_hash[tamanho_tabla]; 

as 4566976 pointed out, tabla_hash[clave_hash] (probably) null. that's guess, haven't provided mcve reproduces issue without having fill in blanks or fix compiler errors...

it seems me though meant declare tablahash so: flujoip tabla_hash[tamanho_tabla]; (though, wow! that's huge array)... , should able change -> . so: tabla_hash[clave_hash].contador++;

alternatively, if precede offending statement if (tablahash[clave_hash] == null) { tablahash[clave_hash] = malloc(sizeof tablahash[clave_hash][0]); } or something, might appropriate... don't forget free of items within huge array.


Comments

Popular posts from this blog

angularjs - ADAL JS Angular- WebAPI add a new role claim to the token -

php - CakePHP HttpSockets send array of paramms -

node.js - Using Node without global install -