Re: Memory error in user-defined aggregation function

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Adriaan Joubert <adriaan(dot)joubert(at)gmail(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Memory error in user-defined aggregation function
Date: 2012-08-07 15:03:41
Message-ID: 17708.1344351821@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Adriaan Joubert <adriaan(dot)joubert(at)gmail(dot)com> writes:
> I've implemented an aggregation function to compute quartiles in C
> borrowing liberally from orafce code. I uses this code in a windowing
> context and it worked fine until today - and I'm not sure what
> changed. This is on 9.1.2 and I have also tried it on 9.1.4.

Hm, it doesn't look very different from what's done in e.g. array_agg.
You do have the transition datatype declared as "internal", no?

I notice that your transition function is sloppy about returning a null
pointer (as opposed to a SQL null) if both input arguments are null.
If all the aggregated values were nulls then the null pointer would
reach the final function and cause a crash similar to the one described.
But that's hardly "not data specific".

> I've recompiled postgres with debugging enabled and have connected to
> the backend with gdb, but haven't had any joy in persuading gdb to
> actually stop in the correct file so that I can step through. I'll
> keep on trying to make some headway with that.

I've found that gdb takes extra persuasion to notice shared libraries
that are loaded after it attaches to the process. Usually the path
of least resistance is to ensure that the library is loaded before
you attach. Use LOAD, or just CREATE OR REPLACE one of the functions
in your library.

regards, tom lane

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Adriaan Joubert 2012-08-07 15:06:36 Re: Memory error in user-defined aggregation function
Previous Message Scott Marlowe 2012-08-07 15:00:30 Re: warnings about invalid "search_path"