Fix memory leak when using justify_hours.
authorBruce Momjian
Thu, 25 Aug 2005 01:30:06 +0000 (01:30 +0000)
committerBruce Momjian
Thu, 25 Aug 2005 01:30:06 +0000 (01:30 +0000)
doc/src/sgml/func.sgml
src/backend/utils/adt/timestamp.c

index fda53ad1295254727b4eaf4296d743ea3d69f848..9bef5e137839cac9d1eb5cb768972f6c6818bed0 100644 (file)
@@ -1,5 +1,5 @@
 
 
@@ -5188,6 +5188,12 @@ SELECT SUBSTRING('XY1234Z', 'Y*?([0-9]{1,3})');
      
     
 
+   
+    If you are using both justify_hours and justify_days,
+    it is best to use justify_hours first so any additional days will
+    justified by justify_days.
+   
+
    
     In addition to these functions, the SQL OVERLAPS operator is
     supported:
index 476923c63647788f00f79df534897a08d9bc3857..7048b491822196fed7d0aa0dedef0a2360121329 100644 (file)
@@ -8,7 +8,7 @@
  *
  *
  * 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)
 {
    Timestamp   dt1 = PG_GETARG_TIMESTAMP(0);
    Timestamp   dt2 = PG_GETARG_TIMESTAMP(1);
-   Interval   *result;
+   Interval   *result, *result2;
 
    result = (Interval *) palloc(sizeof(Interval));
 
@@ -1914,9 +1914,10 @@ timestamp_mi(PG_FUNCTION_ARGS)
    result->month = 0;
    result->day = 0;
 
-   result = DatumGetIntervalP(DirectFunctionCall1(interval_justify_hours,
+   result2 = DatumGetIntervalP(DirectFunctionCall1(interval_justify_hours,
                                                IntervalPGetDatum(result)));
-   PG_RETURN_INTERVAL_P(result);
+   pfree(result);
+   PG_RETURN_INTERVAL_P(result2);
 }
 
 /* interval_justify_hours()
@@ -2263,7 +2264,7 @@ interval_mul(PG_FUNCTION_ARGS)
    Interval   *span = PG_GETARG_INTERVAL_P(0);
    float8      factor = PG_GETARG_FLOAT8(1);
    double      month_remainder, day_remainder;
-   Interval   *result;
+   Interval   *result, *result2;
 
    result = (Interval *) palloc(sizeof(Interval));
 
@@ -2289,9 +2290,10 @@ interval_mul(PG_FUNCTION_ARGS)
                    day_remainder * SECS_PER_DAY);
 #endif
 
-   result = DatumGetIntervalP(DirectFunctionCall1(interval_justify_hours,
+   result2 = DatumGetIntervalP(DirectFunctionCall1(interval_justify_hours,
                                                IntervalPGetDatum(result)));
-   PG_RETURN_INTERVAL_P(result);
+   pfree(result);
+   PG_RETURN_INTERVAL_P(result2);
 }
 
 Datum
@@ -2310,7 +2312,7 @@ interval_div(PG_FUNCTION_ARGS)
    Interval   *span = PG_GETARG_INTERVAL_P(0);
    float8      factor = PG_GETARG_FLOAT8(1);
    double      month_remainder, day_remainder;
-   Interval   *result;
+   Interval   *result, *result2;
 
    result = (Interval *) palloc(sizeof(Interval));
 
@@ -2341,9 +2343,10 @@ interval_div(PG_FUNCTION_ARGS)
    result->time = JROUND(result->time);
 #endif
 
-   result = DatumGetIntervalP(DirectFunctionCall1(interval_justify_hours,
+   result2 = DatumGetIntervalP(DirectFunctionCall1(interval_justify_hours,
                                                IntervalPGetDatum(result)));
-   PG_RETURN_INTERVAL_P(result);
+   pfree(result);
+   PG_RETURN_INTERVAL_P(result2);
 }
 
 /*