Hi, I’m writing a apache module and uses apr hash tables but my hash key keeps getting overwritten, here’s the code I use

 

if(!(torrent = apr_hash_get(torrents,hej->info_hash, 20))) {

torrent = apr_pcalloc(pool, sizeof(struct torrent));

apr_hash_set(torrents, hej->info_hash, 20, torrent); }

 

I set a watchpoint with gdb and the key got overwritten in make_array_core. Here is a backtrace.

 

(gdb) print (char *) 0x820ea20

$183 = 0x820ea20 "wl^\004Uf>\027O2HP<~\"/\220"

(gdb) watch *0x820ea20

Hardware watchpoint 17: *136374816

(gdb) c

Continuing.

Hardware watchpoint 17: *136374816

 

Old value = 73297015

New value = 0

0x403d621b in memset () from /lib/libc.so.6

(gdb) backtrace

#0 0x403d621b in memset () from /lib/libc.so.6

#1 0x4027ecdc in make_array_core (res=0x820ea08, p=0x820d330, nelts=4,

elt_size=8, clear=1) at apr_tables.c:63

#2 0x4027ed8f in apr_array_make (p=0x820d330, nelts=4, elt_size=8)

at apr_tables.c:86

#3 0x0808352d in prep_walk_cache (t=0, r=0x820d368) at request.c:306

#4 0x080838a6 in ap_directory_walk (r=0x820d368) at request.c:511

#5 0x080802af in core_map_to_storage (r=0x820d368) at core.c:3420

#6 0x0808263b in ap_run_map_to_storage (r=0x820d368) at request.c:67

#7 0x08083052 in ap_process_request_internal (r=0x820d368) at request.c:149

#8 0x080666ba in ap_process_request (r=0x820d368) at http_request.c:247

#9 0x08060d63 in ap_process_http_connection (c=0x8207330) at http_core.c:251 #10 0x0807496e in ap_run_process_connection (c=0x8207330) at connection.c:43

#11 0x08074d5c in ap_process_connection (c=0x8207330, csd=0x8207278)

at connection.c:176

#12 0x08068023 in child_main (child_num_arg=0) at prefork.c:610

#13 0x080680fa in make_child (s=0x80a9ea0, slot=0) at prefork.c:650

#14 0x08068222 in startup_children (number_to_start=10) at prefork.c:722

#15 0x0806862b in ap_mpm_run (_pconf=0x80a80f0, plog=0x80d2198, s=0x80a9ea0)

at prefork.c:941

#16 0x0806f239 in main (argc=2, argv=0xbffffb24) at main.c:618

 

Any suggestions how I should fix this?

 

//Andreas