forked frompostgres/postgres
- Notifications
You must be signed in to change notification settings - Fork6
Commit7b86c2a
committed
Improve dubious memory management in pg_newlocale_from_collation().
pg_newlocale_from_collation() used malloc() and strdup() directly,which is generally not per backend coding style, and it didn't botherto check for failure results, but would just SIGSEGV instead. Also,if one of the numerous error checks in the middle of the functionfailed, the already-allocated memory would be leaked permanently.Admittedly, it's not a lot of memory, but it could build up if thisfunction were called repeatedly for a bad collation.The first two problems are easily cured by palloc'ing in TopMemoryContextinstead of calling libc directly. We can fairly easily dodge the leakageproblem for the struct pg_locale_struct by filling in a temporary variableand allocating permanent storage only once we reach the bottom of thefunction. It's harder to get rid of the potential leakage for ICU's copyof the collcollate string, but at least that's only allocated after mostof the error checks; so live with that aspect.Back-patch to v10 where this code came in, with one or another of theICU patches.1 parent4939488 commit7b86c2a
1 file changed
+15
-8
lines changedLines changed: 15 additions & 8 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
1292 | 1292 |
| |
1293 | 1293 |
| |
1294 | 1294 |
| |
1295 |
| - | |
| 1295 | + | |
| 1296 | + | |
1296 | 1297 |
| |
1297 | 1298 |
| |
1298 | 1299 |
| |
| |||
1304 | 1305 |
| |
1305 | 1306 |
| |
1306 | 1307 |
| |
1307 |
| - | |
1308 |
| - | |
1309 |
| - | |
| 1308 | + | |
| 1309 | + | |
| 1310 | + | |
1310 | 1311 |
| |
1311 | 1312 |
| |
1312 | 1313 |
| |
| |||
1353 | 1354 |
| |
1354 | 1355 |
| |
1355 | 1356 |
| |
1356 |
| - | |
| 1357 | + | |
1357 | 1358 |
| |
1358 | 1359 |
| |
1359 | 1360 |
| |
| |||
1379 | 1380 |
| |
1380 | 1381 |
| |
1381 | 1382 |
| |
1382 |
| - | |
1383 |
| - | |
| 1383 | + | |
| 1384 | + | |
| 1385 | + | |
| 1386 | + | |
1384 | 1387 |
| |
1385 | 1388 |
| |
1386 | 1389 |
| |
| |||
1427 | 1430 |
| |
1428 | 1431 |
| |
1429 | 1432 |
| |
1430 |
| - | |
| 1433 | + | |
| 1434 | + | |
| 1435 | + | |
| 1436 | + | |
| 1437 | + | |
1431 | 1438 |
| |
1432 | 1439 |
| |
1433 | 1440 |
| |
|
0 commit comments
Comments
(0)