Commit 4ea18a11 authored by Bruce Momjian's avatar Bruce Momjian

Fix memory leak when using justify_hours.

parent 12c41d7e
<!-- <!--
$PostgreSQL: pgsql/doc/src/sgml/func.sgml,v 1.282 2005/08/24 20:49:35 tgl Exp $ $PostgreSQL: pgsql/doc/src/sgml/func.sgml,v 1.283 2005/08/25 01:29:55 momjian Exp $
PostgreSQL documentation PostgreSQL documentation
--> -->
...@@ -5188,6 +5188,12 @@ SELECT SUBSTRING('XY1234Z', 'Y*?([0-9]{1,3})'); ...@@ -5188,6 +5188,12 @@ SELECT SUBSTRING('XY1234Z', 'Y*?([0-9]{1,3})');
</tgroup> </tgroup>
</table> </table>
<para>
If you are using both <function>justify_hours</> and <function>justify_days</>,
it is best to use <function>justify_hours</> first so any additional days will
justified by <function>justify_days</>.
</para>
<para> <para>
In addition to these functions, the SQL <literal>OVERLAPS</> operator is In addition to these functions, the SQL <literal>OVERLAPS</> operator is
supported: supported:
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/utils/adt/timestamp.c,v 1.148 2005/08/12 18:23:54 tgl Exp $ * $PostgreSQL: pgsql/src/backend/utils/adt/timestamp.c,v 1.149 2005/08/25 01:30:06 momjian Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -1892,7 +1892,7 @@ timestamp_mi(PG_FUNCTION_ARGS) ...@@ -1892,7 +1892,7 @@ timestamp_mi(PG_FUNCTION_ARGS)
{ {
Timestamp dt1 = PG_GETARG_TIMESTAMP(0); Timestamp dt1 = PG_GETARG_TIMESTAMP(0);
Timestamp dt2 = PG_GETARG_TIMESTAMP(1); Timestamp dt2 = PG_GETARG_TIMESTAMP(1);
Interval *result; Interval *result, *result2;
result = (Interval *) palloc(sizeof(Interval)); result = (Interval *) palloc(sizeof(Interval));
...@@ -1914,9 +1914,10 @@ timestamp_mi(PG_FUNCTION_ARGS) ...@@ -1914,9 +1914,10 @@ timestamp_mi(PG_FUNCTION_ARGS)
result->month = 0; result->month = 0;
result->day = 0; result->day = 0;
result = DatumGetIntervalP(DirectFunctionCall1(interval_justify_hours, result2 = DatumGetIntervalP(DirectFunctionCall1(interval_justify_hours,
IntervalPGetDatum(result))); IntervalPGetDatum(result)));
PG_RETURN_INTERVAL_P(result); pfree(result);
PG_RETURN_INTERVAL_P(result2);
} }
/* interval_justify_hours() /* interval_justify_hours()
...@@ -2263,7 +2264,7 @@ interval_mul(PG_FUNCTION_ARGS) ...@@ -2263,7 +2264,7 @@ interval_mul(PG_FUNCTION_ARGS)
Interval *span = PG_GETARG_INTERVAL_P(0); Interval *span = PG_GETARG_INTERVAL_P(0);
float8 factor = PG_GETARG_FLOAT8(1); float8 factor = PG_GETARG_FLOAT8(1);
double month_remainder, day_remainder; double month_remainder, day_remainder;
Interval *result; Interval *result, *result2;
result = (Interval *) palloc(sizeof(Interval)); result = (Interval *) palloc(sizeof(Interval));
...@@ -2289,9 +2290,10 @@ interval_mul(PG_FUNCTION_ARGS) ...@@ -2289,9 +2290,10 @@ interval_mul(PG_FUNCTION_ARGS)
day_remainder * SECS_PER_DAY); day_remainder * SECS_PER_DAY);
#endif #endif
result = DatumGetIntervalP(DirectFunctionCall1(interval_justify_hours, result2 = DatumGetIntervalP(DirectFunctionCall1(interval_justify_hours,
IntervalPGetDatum(result))); IntervalPGetDatum(result)));
PG_RETURN_INTERVAL_P(result); pfree(result);
PG_RETURN_INTERVAL_P(result2);
} }
Datum Datum
...@@ -2310,7 +2312,7 @@ interval_div(PG_FUNCTION_ARGS) ...@@ -2310,7 +2312,7 @@ interval_div(PG_FUNCTION_ARGS)
Interval *span = PG_GETARG_INTERVAL_P(0); Interval *span = PG_GETARG_INTERVAL_P(0);
float8 factor = PG_GETARG_FLOAT8(1); float8 factor = PG_GETARG_FLOAT8(1);
double month_remainder, day_remainder; double month_remainder, day_remainder;
Interval *result; Interval *result, *result2;
result = (Interval *) palloc(sizeof(Interval)); result = (Interval *) palloc(sizeof(Interval));
...@@ -2341,9 +2343,10 @@ interval_div(PG_FUNCTION_ARGS) ...@@ -2341,9 +2343,10 @@ interval_div(PG_FUNCTION_ARGS)
result->time = JROUND(result->time); result->time = JROUND(result->time);
#endif #endif
result = DatumGetIntervalP(DirectFunctionCall1(interval_justify_hours, result2 = DatumGetIntervalP(DirectFunctionCall1(interval_justify_hours,
IntervalPGetDatum(result))); IntervalPGetDatum(result)));
PG_RETURN_INTERVAL_P(result); pfree(result);
PG_RETURN_INTERVAL_P(result2);
} }
/* /*
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment