This has the same problem as the otherone I commented on. Since you are not passing the length here, add_assoc_string() does a strlen(key_str), but to_index_string() can return a NULL, so the result becomes strlen(NULL).