I was wrong, the 3rd parameter (hash) to ngx_http_get_variable is not optional even if the variable name is indicated in 2nd parameter.
static unsigned
get_ip_country(ngx_http_request_t *r, ngx_str_t *geoip_country_code){
ngx_str_t variable_name = ngx_string("geoip_country_code");
ngx_int_t hash = ngx_hash_key (variable_name.data, variable_name.len);
ngx_http_variable_value_t * geoip_country_code_var = ngx_http_get_variable( r, &variable_name, hash);
if( geoip_country_code_var && !geoip_country_code_var->not_found && geoip_country_code_var->valid){
geoip_country_code->data = ngx_palloc( r->pool, geoip_country_code_var->len);
geoip_country_code->len = geoip_country_code_var->len;
ngx_strlow( geoip_country_code->data, geoip_country_code_var->data, geoip_country_code->len);
return 1;
}
return 0;
}