segmentation fault - C: "Invalid free(): Address 0x7feffee08 is on thread 1's stack" -


this not exact code, in essence. i'm trying create stack variable in main()

int **x;

that want pass function foo(int **x, arg1, arg2, ...). on condition, i'm supposed dynamically allocate space x in foo()

x = (int **) malloc(sizeof(int *) * num_elems);

i not allocating new space each int * element, assigning &y, int y created in foo().

i got error when tried freeing x in main(). don't understand means, suspect might because used &y?

edit: relevant: got garbage values when tried accessing double-dereferenced elements of x.

you not correctly declared in main function , not correctly defined in foo() function. have declare as

in main function

int *x ; foo(&x); 

in foo(int **x,....)

*x =  malloc(sizeof(int) * num_elems); 

Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -