Fix write-past-buffer-end in ldapServiceLookup().
Fix write-past-buffer-end in ldapServiceLookup().

The code to assemble ldap_get_values_len's output into a single string
wrote the terminating null one byte past where it should.  Fix that,
and make some other cosmetic adjustments to make the code a trifle more
readable and more in line with usual Postgres coding style.

Also, free the "result" string when done with it, to avoid a permanent
memory leak.

Bug report and patch by Albe Laurenz, cosmetic adjustments by me.

Chibin/gpdb,royc1/gpdb,janebeckman/gpdb,zaksoup/gpdb,cjcjameson/gpdb,ahachete/gpdb,0x0FFF/gpdb,lisakowen/gpdb,50wu/gpdb,CraigHarris/gpdb,Chibin/gpdb,edespino/gpdb,0x0FFF/gpdb,lisakowen/gpdb,lintzc/gpdb,chrishajas/gpdb,adam8157/gpdb,CraigHarris/gpdb,adam8157/gpdb,0x0FFF/gpdb,edespino/gpdb,0x0FFF/gpdb,0x0FFF/gpdb,edespino/gpdb,zaksoup/gpdb,janebeckman/gpdb,Chibin/gpdb,janebeckman/gpdb,CraigHarris/gpdb,50wu/gpdb,ahachete/gpdb,ahachete/gpdb,xinzweb/gpdb,Quikling/gpdb,cjcjameson/gpdb,zaksoup/gpdb,yuanzhao/gpdb,ashwinstar/gpdb,chrishajas/gpdb,lintzc/gpdb,Quikling/gpdb,xinzweb/gpdb,edespino/gpdb,Quikling/gpdb,ashwinstar/gpdb,ashwinstar/gpdb,lintzc/gpdb,lintzc/gpdb,Chibin/gpdb,rvs/gpdb,ashwinstar/gpdb,kaknikhil/gpdb,cjcjameson/gpdb,adam8157/gpdb,chrishajas/gpdb,xuegang/gpdb,CraigHarris/gpdb,adam8157/gpdb,kaknikhil/gpdb,jmcatamney/gpdb,jmcatamney/gpdb,xinzweb/gpdb,lisakowen/gpdb,cjcjameson/gpdb,xuegang/gpdb,ahachete/gpdb,rvs/gpdb,zaksoup/gpdb,CraigHarris/gpdb,janebeckman/gpdb,Quikling/gpdb,lintzc/gpdb,kaknikhil/gpdb,Quikling/gpdb,edespino/gpdb,greenplum-db/gpdb,rvs/gpdb,rvs/gpdb,jmcatamney/gpdb,cjcjameson/gpdb,Quikling/gpdb,cjcjameson/gpdb,janebeckman/gpdb,yuanzhao/gpdb,ahachete/gpdb,CraigHarris/gpdb,rvs/gpdb,janebeckman/gpdb,royc1/gpdb,edespino/gpdb,greenplum-db/gpdb,xuegang/gpdb,adam8157/gpdb,Quikling/gpdb,chrishajas/gpdb,yuanzhao/gpdb,yuanzhao/gpdb,jmcatamney/gpdb,rvs/gpdb,adam8157/gpdb,greenplum-db/gpdb,adam8157/gpdb,jmcatamney/gpdb,edespino/gpdb,cjcjameson/gpdb,Chibin/gpdb,janebeckman/gpdb,Chibin/gpdb,50wu/gpdb,lisakowen/gpdb,janebeckman/gpdb,xuegang/gpdb,janebeckman/gpdb,xuegang/gpdb,kaknikhil/gpdb,Chibin/gpdb,CraigHarris/gpdb,xinzweb/gpdb,yuanzhao/gpdb,royc1/gpdb,yuanzhao/gpdb,greenplum-db/gpdb,chrishajas/gpdb,50wu/gpdb,zaksoup/gpdb,rvs/gpdb,lisakowen/gpdb,Chibin/gpdb,Quikling/gpdb,royc1/gpdb,chrishajas/gpdb,lisakowen/gpdb,lisakowen/gpdb,adam8157/gpdb,edespino/gpdb,50wu/gpdb,royc1/gpdb,cjcjameson/gpdb,ahachete/gpdb,rvs/gpdb,kaknikhil/gpdb,zaksoup/gpdb,zaksoup/gpdb,zaksoup/gpdb,cjcjameson/gpdb,jmcatamney/gpdb,xuegang/gpdb,chrishajas/gpdb,cjcjameson/gpdb,xinzweb/gpdb,ashwinstar/gpdb,Quikling/gpdb,greenplum-db/gpdb,Chibin/gpdb,yuanzhao/gpdb,greenplum-db/gpdb,jmcatamney/gpdb,yuanzhao/gpdb,lintzc/gpdb,edespino/gpdb,ashwinstar/gpdb,jmcatamney/gpdb,lintzc/gpdb,kaknikhil/gpdb,Quikling/gpdb,janebeckman/gpdb,rvs/gpdb,Chibin/gpdb,kaknikhil/gpdb,kaknikhil/gpdb,50wu/gpdb,50wu/gpdb,ahachete/gpdb,ashwinstar/gpdb,ashwinstar/gpdb,edespino/gpdb,greenplum-db/gpdb,kaknikhil/gpdb,kaknikhil/gpdb,xinzweb/gpdb,royc1/gpdb,xinzweb/gpdb,xuegang/gpdb,xinzweb/gpdb,xuegang/gpdb,royc1/gpdb,xuegang/gpdb,CraigHarris/gpdb,0x0FFF/gpdb,chrishajas/gpdb,royc1/gpdb,CraigHarris/gpdb,0x0FFF/gpdb,lisakowen/gpdb,rvs/gpdb,greenplum-db/gpdb,yuanzhao/gpdb,yuanzhao/gpdb,ahachete/gpdb,lintzc/gpdb,50wu/gpdb,lintzc/gpdb,0x0FFF/gpdb