Malloc only works with valgrind on. How to debug?

104 Views Asked by At

to put you in some context here, project i test with valgrind is slightly modified version of distcc. The function that fails has not been changed. The exact place in code that is problematic is function dcc_compress_file_lzo1x in compress.c. It goes like this:

int dcc_compress_file_lzo1x(int in_fd,
                        size_t in_len,
                        char **out_buf,
                        size_t *out_len)
{
char *in_buf = NULL;
int ret;

if ((in_buf = malloc(in_len)) == NULL) {
    rs_log_error("allocation of %ld byte buffer failed",
                 (long) in_len);
    ret = EXIT_OUT_OF_MEMORY;
    goto out;
}

The problem here is malloc in if statement. If I run this program normally it fails randomly(I wrapped whole thing in debug prints), by which i mean that program crashes while doing malloc, without producing error print. On the other hand if i start program with valgrind, everything passes and valgrind doesn't produce anything useful.

I'm not looking for easy answer. I would just like to know how to even debug this, because I'm out of ideas.

0

There are 0 best solutions below