Don't understand why valgrind is giving an error here.
Hi,
I've looked through the valgrind documentation, but I just can't see anything wrong with this line of code:
Code:
int*
get_replica_ids(const Replica *replicas, int num_replicas)
{
int *ids = (int*)malloc(sizeof(int) * num_replicas);
if(!ids){
fprintf(stderr, "Could not allocate memory for id array.\n");
return NULL;
}
int i;
for(i = 0; i<num_replicas; i++){
ids[i] = replicas[i].replica_id;
}
return ids;
}
it's giving an error the if(!ids) line.
The error is
Quote:
Address 0x6a43f38 is 0 bytes after a block of size 8 alloc'd
Any idea?