According to the documentation at:
https://wiki.sei.cmu.edu/confluence/display/c/POS34-C.+Do+not+call+putenv%28%29+with+a+pointer+to+an+automatic+variable+as+the+argument
"Using setenv() is easier and consequently less error prone than using putenv()."
putenv is problematic and error prone, better replace by setenv.
As a result, set_pglocale_pgservice, is much simpler and more readable.
regards,
Ranier Vilela