Skip to content

Commit 4ea18a1

Browse files
committed
Fix memory leak when using justify_hours.
1 parent 12c41d7 commit 4ea18a1

File tree

2 files changed

+20
-11
lines changed

2 files changed

+20
-11
lines changed

doc/src/sgml/func.sgml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<!--
2-
$PostgreSQL: pgsql/doc/src/sgml/func.sgml,v 1.282 2005/08/24 20:49:35 tgl Exp $
2+
$PostgreSQL: pgsql/doc/src/sgml/func.sgml,v 1.283 2005/08/25 01:29:55 momjian Exp $
33
PostgreSQL documentation
44
-->
55

@@ -5188,6 +5188,12 @@ SELECT SUBSTRING('XY1234Z', 'Y*?([0-9]{1,3})');
51885188
</tgroup>
51895189
</table>
51905190

5191+
<para>
5192+
If you are using both <function>justify_hours</> and <function>justify_days</>,
5193+
it is best to use <function>justify_hours</> first so any additional days will
5194+
justified by <function>justify_days</>.
5195+
</para>
5196+
51915197
<para>
51925198
In addition to these functions, the SQL <literal>OVERLAPS</> operator is
51935199
supported:

src/backend/utils/adt/timestamp.c

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/utils/adt/timestamp.c,v 1.148 2005/08/12 18:23:54 tgl Exp $
11+
* $PostgreSQL: pgsql/src/backend/utils/adt/timestamp.c,v 1.149 2005/08/25 01:30:06 momjian Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -1892,7 +1892,7 @@ timestamp_mi(PG_FUNCTION_ARGS)
18921892
{
18931893
Timestamp dt1 = PG_GETARG_TIMESTAMP(0);
18941894
Timestamp dt2 = PG_GETARG_TIMESTAMP(1);
1895-
Interval *result;
1895+
Interval *result, *result2;
18961896

18971897
result = (Interval *) palloc(sizeof(Interval));
18981898

@@ -1914,9 +1914,10 @@ timestamp_mi(PG_FUNCTION_ARGS)
19141914
result->month = 0;
19151915
result->day = 0;
19161916

1917-
result = DatumGetIntervalP(DirectFunctionCall1(interval_justify_hours,
1917+
result2 = DatumGetIntervalP(DirectFunctionCall1(interval_justify_hours,
19181918
IntervalPGetDatum(result)));
1919-
PG_RETURN_INTERVAL_P(result);
1919+
pfree(result);
1920+
PG_RETURN_INTERVAL_P(result2);
19201921
}
19211922

19221923
/* interval_justify_hours()
@@ -2263,7 +2264,7 @@ interval_mul(PG_FUNCTION_ARGS)
22632264
Interval *span = PG_GETARG_INTERVAL_P(0);
22642265
float8 factor = PG_GETARG_FLOAT8(1);
22652266
double month_remainder, day_remainder;
2266-
Interval *result;
2267+
Interval *result, *result2;
22672268

22682269
result = (Interval *) palloc(sizeof(Interval));
22692270

@@ -2289,9 +2290,10 @@ interval_mul(PG_FUNCTION_ARGS)
22892290
day_remainder * SECS_PER_DAY);
22902291
#endif
22912292

2292-
result = DatumGetIntervalP(DirectFunctionCall1(interval_justify_hours,
2293+
result2 = DatumGetIntervalP(DirectFunctionCall1(interval_justify_hours,
22932294
IntervalPGetDatum(result)));
2294-
PG_RETURN_INTERVAL_P(result);
2295+
pfree(result);
2296+
PG_RETURN_INTERVAL_P(result2);
22952297
}
22962298

22972299
Datum
@@ -2310,7 +2312,7 @@ interval_div(PG_FUNCTION_ARGS)
23102312
Interval *span = PG_GETARG_INTERVAL_P(0);
23112313
float8 factor = PG_GETARG_FLOAT8(1);
23122314
double month_remainder, day_remainder;
2313-
Interval *result;
2315+
Interval *result, *result2;
23142316

23152317
result = (Interval *) palloc(sizeof(Interval));
23162318

@@ -2341,9 +2343,10 @@ interval_div(PG_FUNCTION_ARGS)
23412343
result->time = JROUND(result->time);
23422344
#endif
23432345

2344-
result = DatumGetIntervalP(DirectFunctionCall1(interval_justify_hours,
2346+
result2 = DatumGetIntervalP(DirectFunctionCall1(interval_justify_hours,
23452347
IntervalPGetDatum(result)));
2346-
PG_RETURN_INTERVAL_P(result);
2348+
pfree(result);
2349+
PG_RETURN_INTERVAL_P(result2);
23472350
}
23482351

23492352
/*

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy