|
10 | 10 | #include "ecpgtype.h"
|
11 | 11 | #include "sqlca.h"
|
12 | 12 |
|
| 13 | +#ifdef HAVE_USELOCALE |
| 14 | +locale_t ecpg_clocale = (locale_t) 0; |
| 15 | +#endif |
| 16 | + |
13 | 17 | static pthread_mutex_t connections_mutex = PTHREAD_MUTEX_INITIALIZER;
|
14 | 18 | static pthread_key_t actual_connection_key;
|
15 | 19 | static pthread_once_t actual_connection_key_once = PTHREAD_ONCE_INIT;
|
@@ -264,7 +268,7 @@ ECPGconnect(int lineno, int c, const char *name, const char *user, const char *p
|
264 | 268 | const char **conn_keywords;
|
265 | 269 | const char **conn_values;
|
266 | 270 |
|
267 |
| - if (sqlca == NULL || !pg_ensure_c_locale()) |
| 271 | + if (sqlca == NULL) |
268 | 272 | {
|
269 | 273 | ecpg_raise(lineno, ECPG_OUT_OF_MEMORY,
|
270 | 274 | ECPG_SQLSTATE_ECPG_OUT_OF_MEMORY, NULL);
|
@@ -479,6 +483,39 @@ ECPGconnect(int lineno, int c, const char *name, const char *user, const char *p
|
479 | 483 | /* add connection to our list */
|
480 | 484 | pthread_mutex_lock(&connections_mutex);
|
481 | 485 |
|
| 486 | + /* |
| 487 | + * ... but first, make certain we have created ecpg_clocale. Rely on |
| 488 | + * holding connections_mutex to ensure this is done by only one thread. |
| 489 | + */ |
| 490 | +#ifdef HAVE_USELOCALE |
| 491 | + if (!ecpg_clocale) |
| 492 | + { |
| 493 | + ecpg_clocale = newlocale(LC_NUMERIC_MASK, "C", (locale_t) 0); |
| 494 | + if (!ecpg_clocale) |
| 495 | + { |
| 496 | + pthread_mutex_unlock(&connections_mutex); |
| 497 | + ecpg_raise(lineno, ECPG_OUT_OF_MEMORY, |
| 498 | + ECPG_SQLSTATE_ECPG_OUT_OF_MEMORY, NULL); |
| 499 | + if (host) |
| 500 | + ecpg_free(host); |
| 501 | + if (port) |
| 502 | + ecpg_free(port); |
| 503 | + if (options) |
| 504 | + ecpg_free(options); |
| 505 | + if (realname) |
| 506 | + ecpg_free(realname); |
| 507 | + if (dbname) |
| 508 | + ecpg_free(dbname); |
| 509 | + if (conn_keywords) |
| 510 | + ecpg_free(conn_keywords); |
| 511 | + if (conn_values) |
| 512 | + ecpg_free(conn_values); |
| 513 | + free(this); |
| 514 | + return false; |
| 515 | + } |
| 516 | + } |
| 517 | +#endif |
| 518 | + |
482 | 519 | if (connection_name != NULL)
|
483 | 520 | this->name = ecpg_strdup(connection_name, lineno);
|
484 | 521 | else
|
|
0 commit comments