Skip to content

Commit d8d39cc

Browse files
author
Masahiko Sakamoto
committed
Fix memory leak and wrong usage of StringInfo in pgut_connect().
1 parent 7865250 commit d8d39cc

File tree

5 files changed

+96
-13
lines changed

5 files changed

+96
-13
lines changed

SPECS/pg_reorg.spec renamed to SPECS/pg_reorg84.spec

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
Summary: Reorganize tables in PostgreSQL databases without any locks.
66
Name: %{sname}
7-
Version: 1.1.4
7+
Version: 1.1.5
88
Release: 1%{?dist}
99
License: BSD
1010
Group: Applications/Databases
@@ -13,7 +13,7 @@ URL: http://pgfoundry.org/projects/%{sname}/
1313
BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-%(%{__id_u} -n)
1414

1515
BuildRequires: postgresql-devel, postgresql
16-
Requires: postgresql
16+
Requires: postgresql, postgresql-libs
1717

1818
%description
1919
pg_reorg can re-organize tables on a postgres database without any locks so that
@@ -28,7 +28,11 @@ USE_PGXS=1 make %{?_smp_mflags}
2828

2929
%install
3030
rm -rf %{buildroot}
31-
USE_PGXS=1 make DESTDIR=%{buildroot} install
31+
USE_PGXS=1 make DESTDIR=%{buildroot}
32+
33+
install -d %{buildroot}%{_libdir}/pgsql
34+
install -d %{buildroot}%{_bindir}
35+
install -d %{buildroot}%{_datadir}/pgsql/contrib
3236

3337
install -m 755 bin/pg_reorg %{buildroot}%{_bindir}/pg_reorg
3438
install -m 755 lib/pg_reorg.so %{buildroot}%{_libdir}/pgsql/pg_reorg.so
@@ -49,6 +53,7 @@ install -m 644 lib/uninstall_pg_reorg.sql %{buildroot}%{_datadir}/pgsql/contrib/
4953
rm -rf %{buildroot}
5054

5155
%changelog
56+
* Thu Oct 21 2010 - NTT OSS Center <sakamoto.masahiko@oss.ntt.co.jp> 1.1.5-1
5257
* Wed Sep 22 2010 - NTT OSS Center <sakamoto.masahiko@oss.ntt.co.jp> 1.1.4-1
5358
* Thu Apr 22 2010 - NTT OSS Center <itagaki.takahiro@oss.ntt.co.jp> 1.1.2-1
5459
* Mon Jan 15 2010 - Toru SHIMOGAKI <shimogaki.toru@oss.ntt.co.jp> 1.0.8-1

SPECS/pg_reorg90.spec

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
# SPEC file for pg_reorg
2+
# Copyright(C) 2009-2010 NIPPON TELEGRAPH AND TELEPHONE CORPORATION
3+
%define sname pg_reorg
4+
5+
%define _pgdir /usr/pgsql-9.0
6+
%define _bindir %{_pgdir}/bin
7+
%define _libdir %{_pgdir}/lib
8+
%define _datadir %{_pgdir}/share
9+
10+
Summary: Reorganize tables in PostgreSQL databases without any locks.
11+
Name: %{sname}
12+
Version: 1.1.5
13+
Release: 1%{?dist}
14+
License: BSD
15+
Group: Applications/Databases
16+
Source0: %{sname}-%{version}.tar.gz
17+
URL: http://pgfoundry.org/projects/%{sname}/
18+
BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-%(%{__id_u} -n)
19+
20+
BuildRequires: postgresql90-devel, postgresql90
21+
Requires: postgresql90, postgresql90-libs
22+
23+
%description
24+
pg_reorg can re-organize tables on a postgres database without any locks so that
25+
you can retrieve or update rows in tables being reorganized.
26+
The module is developed to be a better alternative of CLUSTER and VACUUM FULL.
27+
28+
%prep
29+
%setup -q -n %{sname}-%{version}
30+
31+
%build
32+
USE_PGXS=1 make %{?_smp_mflags}
33+
34+
%install
35+
rm -rf %{buildroot}
36+
USE_PGXS=1 make DESTDIR=%{buildroot}
37+
38+
install -d %{buildroot}%{_libdir}
39+
install -d %{buildroot}%{_bindir}
40+
install -d %{buildroot}%{_datadir}/contrib
41+
42+
install -m 755 bin/pg_reorg %{buildroot}%{_bindir}/pg_reorg
43+
install -m 755 lib/pg_reorg.so %{buildroot}%{_libdir}/pg_reorg.so
44+
install -m 644 lib/pg_reorg.sql %{buildroot}%{_datadir}/contrib/pg_reorg.sql
45+
install -m 644 lib/uninstall_pg_reorg.sql %{buildroot}%{_datadir}/contrib/uninstall_pg_reorg.sql
46+
47+
%define pg_sharedir
48+
49+
%files
50+
%defattr(755,root,root,755)
51+
%{_bindir}/pg_reorg
52+
%{_libdir}/pg_reorg.so
53+
%defattr(644,root,root,755)
54+
%{_datadir}/contrib/pg_reorg.sql
55+
%{_datadir}/contrib/uninstall_pg_reorg.sql
56+
57+
%clean
58+
rm -rf %{buildroot}
59+
60+
%changelog
61+
* Thu Oct 21 2010 - NTT OSS Center <sakamoto.masahiko@oss.ntt.co.jp> 1.1.5-1
62+
* Wed Sep 22 2010 - NTT OSS Center <sakamoto.masahiko@oss.ntt.co.jp> 1.1.4-1
63+
* Thu Apr 22 2010 - NTT OSS Center <itagaki.takahiro@oss.ntt.co.jp> 1.1.2-1
64+
* Mon Jan 15 2010 - Toru SHIMOGAKI <shimogaki.toru@oss.ntt.co.jp> 1.0.8-1
65+
* Tue Sep 08 2009 - Toru SHIMOGAKI <shimogaki.toru@oss.ntt.co.jp> 1.0.6-1
66+
* Fri May 15 2009 - Toru SHIMOGAKI <shimogaki.toru@oss.ntt.co.jp> 1.0.4-1
67+
- Initial packaging

bin/pg_reorg.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
* @brief Client Modules
99
*/
1010

11-
const char *PROGRAM_VERSION = "1.1.3";
11+
const char *PROGRAM_VERSION = "1.1.5";
1212
const char *PROGRAM_URL = "http://reorg.projects.postgresql.org/";
1313
const char *PROGRAM_EMAIL = "reorg-general@lists.pgfoundry.org";
1414

bin/pgut/pgut.c

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -408,19 +408,22 @@ pgut_connect(const char *info, YesNo prompt, int elevel)
408408
{
409409
passwd = prompt_for_password();
410410
initStringInfo(&add_pass);
411-
appendStringInfo(&add_pass, info);
411+
appendStringInfoString(&add_pass, info);
412412
appendStringInfo(&add_pass, " password=%s ", passwd);
413413
}
414414
else
415+
{
415416
passwd = NULL;
417+
add_pass.data = NULL;
418+
}
416419

417420
/* Start the connection. Loop until we have a password if requested by backend. */
418421
for (;;)
419422
{
420423
PGconn *conn;
421424
CHECK_FOR_INTERRUPTS();
422425

423-
if(!passwd)
426+
if (!passwd)
424427
conn = PQconnectdb(info);
425428
else
426429
conn = PQconnectdb(add_pass.data);
@@ -438,10 +441,10 @@ pgut_connect(const char *info, YesNo prompt, int elevel)
438441
pgut_connections = c;
439442
pgut_conn_unlock();
440443

441-
if(passwd)
444+
if (add_pass.data != NULL)
442445
termStringInfo(&add_pass);
443-
444446
free(passwd);
447+
445448
return conn;
446449
}
447450

@@ -450,11 +453,19 @@ pgut_connect(const char *info, YesNo prompt, int elevel)
450453
PQfinish(conn);
451454
free(passwd);
452455
passwd = prompt_for_password();
453-
initStringInfo(&add_pass);
454-
appendStringInfo(&add_pass, info);
456+
if (add_pass.data != NULL)
457+
resetStringInfo(&add_pass);
458+
else
459+
initStringInfo(&add_pass);
460+
appendStringInfoString(&add_pass, info);
455461
appendStringInfo(&add_pass, " password=%s ", passwd);
456462
continue;
457463
}
464+
465+
if (add_pass.data != NULL)
466+
termStringInfo(&add_pass);
467+
free(passwd);
468+
458469
ereport(elevel,
459470
(errcode(E_PG_CONNECT),
460471
errmsg("could not connect to database with \"%s\": %s",

lib/reorg.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ static void RenameRelationInternal(Oid myrelid, const char *newrelname, Oid name
7575
Datum
7676
reorg_version(PG_FUNCTION_ARGS)
7777
{
78-
return CStringGetTextDatum("pg_reorg 1.1.2");
78+
return CStringGetTextDatum("pg_reorg 1.1.5");
7979
}
8080

8181
/**
@@ -605,7 +605,7 @@ remove_dropped_columns_and_adjust_attnum(Oid oid, int16 natts1, int16 natts2)
605605
natts2 - natts1, SPI_processed);
606606

607607
/* renumber attnum */
608-
#if PG_VERSION_NUM >= 80500
608+
#if PG_VERSION_NUM >= 90000
609609
execute_with_format(SPI_OK_UPDATE,
610610
"UPDATE pg_catalog.pg_attribute m"
611611
" SET attnum = (SELECT count(*) FROM pg_attribute a"
@@ -802,7 +802,7 @@ reorg_swap(PG_FUNCTION_ARGS)
802802
/* adjust key attnum if the target table has dropped columns */
803803
if (natts1 != natts2)
804804
{
805-
#if PG_VERSION_NUM >= 80500
805+
#if PG_VERSION_NUM >= 90000
806806
execute_with_format(SPI_OK_UPDATE,
807807
"UPDATE pg_catalog.pg_index m SET indkey = n.indkey"
808808
" FROM pg_catalog.pg_index n"

0 commit comments

Comments
 (0)