views:

82

answers:

3

Hi,

I have this strange behaviour in Apache post_config handler :

int setup_module(apr_pool_t *p, apr_pool_t *plog, apr_pool_t *ptemp,server_rec *s)
{
    //1
    my_config_t *config =  ap_get_module_config(s->module_config, &my_module);

    //2
    log_me(config->logfp, apr_psprintf(ptemp, "My module version %s\n", MY_VERSION));

    //3
    log_me(config->logfp, "Starting the batch job");

    return OK;
}

log_me is a custom function declared in another file and declared in the header (it is resolved at compile time).

In the step2 I can see that config has a valid value, however step 3 fails with a SEGSEGV and if I try to debug it I can see this :

//step 2 gdb: print config $1 = (my_config_t *)0x7a8098

//step 3 gdb: print config Cannot access memory at address 0x38

A: 

Something is overwriting the config pointer. Can you put a breakpoint on the memory location and see what is executing the overwrite? Here's a guide to how to do this: http://www.technochakra.com/debugging-types-of-data-breakpoints-in-gdb/

mikelong
I debugged the function and I'm sure that there is no write on that variable...
Alin
A: 

I've found teh problem.

In log_me I was making :

int nbytes = strlen(message);

instead of:

apr_size_t nbytes = strlen(message);

Being on 64 bits this screwed all.. no idea why yet.

Alin
It doesn't seem likely that was the real problem. It is more likely that it shifted stack or memory usage around and hid the problem.
Mark Wilkins
Actually if i commented this handler i had no issues.Also this module worked perfectly on Solaris 10 with default 32 bit (gcc, apache and LD library path). Here I have all on 64
Alin
Maybe you're not including `string.h` in the file containing `log_me`?
Alok
it is included.. this and apr_string.h...
Alin
+1  A: 

What is ptemp passed into setup_module, and is it safe to use it as a buffer for your sprintf? Is it possible ptemp points to a memory area that isn't large enough to hold that string?

Maybe you should declare an auto variable (char buffer[80];) and use that for your sprintf?

tomlogic
ptemp is a temporary memory pool cleared after the config phase. apr_psprintf is a function providd by apr (Apache portable runtime) and should not have buffer issues like you are mentioning
Alin