Valgrind says "stack allocation", I say "heap allocation"

I am trying to trace segfault with valgrind. I get the following message from valgrind:

==3683== Conditional jump or move depends on uninitialised value(s) ==3683== at 0x4C277C5: sparse_mat_mat_kron (sparse.c:165) ==3683== by 0x4C2706E: rec_mating (rec.c:176) ==3683== by 0x401C1C: age_dep_iterate (age_dep.c:287) ==3683== by 0x4014CB: main (age_dep.c:92) ==3683== Uninitialised value was created by a stack allocation ==3683== at 0x401848: age_dep_init_params (age_dep.c:131) ==3683== ==3683== Conditional jump or move depends on uninitialised value(s) ==3683== at 0x4C277C7: sparse_mat_mat_kron (sparse.c:165) ==3683== by 0x4C2706E: rec_mating (rec.c:176) ==3683== by 0x401C1C: age_dep_iterate (age_dep.c:287) ==3683== by 0x4014CB: main (age_dep.c:92) ==3683== Uninitialised value was created by a stack allocation ==3683== at 0x401848: age_dep_init_params (age_dep.c:131) 

However, here is an offensive line:

  /* allocate mating table */ age_dep_data->mtable = malloc (age_dep_data->geno * sizeof (double *)); if (age_dep_data->mtable == NULL) error (ENOMEM, ENOMEM, nullmsg, __LINE__); for (int j = 0; j < age_dep_data->geno; j++) { 131=> age_dep_data->mtable[j] = calloc (age_dep_data->geno, sizeof (double)); if (age_dep_data->mtable[j] == NULL) error (ENOMEM, ENOMEM, nullmsg, __LINE__); } 

What gives? I thought that any call in malloc or calloc allocates a bunch of space; there is no other variable, right? Is it possible that another distribution occurs (allocating a stack for violation) that I do not see?

EDIT: my current suspicion is the array allocated by the stack: I declare a pointer to a double (stack), and then assign it the result of a function that returns double *. Then I put it in the previously allocated location.

I can’t memmove, memcpy or assign a stack variable, then hope it persists, right?

+7
c malloc calloc valgrind
source share
3 answers

Since then I discovered that this valgrind error

 Conditional jump or move depends on uninitialised value(s) 

occurs all the time and is not a source of error. It seems to be a red herring, in most cases I came across after posting this question.

-one
source share

I don’t know what the problem is, but

 -track-origins=yes 

can help you get more information about what he complains about; see this blog entry: http://blog.mozilla.com/nnethercote/2009/02/27/eliminating-undefined-values-with-valgrind-the-easy-way/

+2
source share

possible reason:
you define age_dep_data->mtable as double* but it should be double** as an array of arrays

0
source share

All Articles