On Wed, Oct 18, 2006 at 02:56:25AM -0700, Gisle Aas wrote:
> We have been tracking down a DBI segfault that was causing trouble for
> a customer of ours. Does this patch relative to DBI-1.52 look right
> to you?
Thanks Gisle. Looks okay at first sight. I'll take a deeper look later.
What's really needed is a hook for drivers to call when they want to
'reset' a statement handle to a virgin state ready for a new result set
(with different columns etc).
Without that there may be subtle issues if the driver don't take care
to do all the required steps - such as clearing the cached attributes
like $sth->{NAME}.
Tim.
> More information and test case at:
>
> http://rt.cpan.org/Ticket/Display.html?id=22150
>
> Fix segfault for multiple result sets when later sets grow more
> fields. DBI assumes the number of fields stay the same for a
> statement handle.
>
> Index: DBI.xs
> --- DBI.xs.~1~ Wed Oct 18 11:40:48 2006
> +++ DBI.xs Wed Oct 18 11:40:48 2006
> @@ -1370,9 +1370,9 @@
>
> if ( (av = DBIc_FIELDS_AV(imp_sth)) == Nullav)
> av = dbih_setup_fbav(imp_sth);
> -
> - if (1) { /* XXX turn into option later */
> - int i = DBIc_NUM_FIELDS(imp_sth);
> + else { /* XXX turn into option later */
> + dTHX;
> + int i = av_len(av) + 1;
> /* don't let SvUTF8 flag persist from one row to the next */
> /* (only affects drivers that use sv_setpv, but most XS do) */
> while(i--) /* field 1 stored at index 0 */
> End of Patch.
>
> Regards,
> Gisle Aas,
> ActiveState