The result of the select query is freed in setsampwent before it can be read by subsequent calls to getsampwent. The patch corrects that. Since the structure is still freed in the final call to endsampwent all should be fine.
Created attachment 1453 [details] Removes the if clause in pdb_pgsql.c/setsampwent() that frees the SELECT result before it's ever used
Maybe this new bug is of interest for those on the Cc list: https://bugzilla.samba.org/show_bug.cgi?id=3351
See bug 3375. If someone wants to maintain these modules outside the Samba source tree, that is fine. But the source has been removed from the upcoming 3.0.22 release.