The point here is that cupsGetDests builds a cups_dest_t array with
names, options names and values that are shared (when two printers has
the same name, the name is written in the same memory location and the
two corresponding cups_dest_t has the same 'name' pointer value).
A (dirty) solution could be to clone the cups_dest_t to make new copies
of these values, as in the attached patch.
Regards,
Alexis.
--- a/CUPS.xs 2009-07-30 15:42:59.000000000 +0200
+++ b/CUPS.xs.a 2014-10-23 10:53:21.149958633 +0200
@@ -48,6 +48,21 @@
return password;
}
+cups_dest_t* cupsCloneDest(cups_dest_t* src) {
+ int i;
+ cups_dest_t *dst=malloc(sizeof(cups_dest_t));
+ memcpy(dst,src,sizeof(cups_dest_t));
+ if(src->name!=NULL) dst->name=strdup(src->name);
+ if(src->instance!=NULL) dst->instance=strdup(src->instance);
+ dst->options=malloc(src->num_options*sizeof(cups_option_t));
+ for(i=0;i<src->num_options;i++) {
+ memcpy(&dst->options[i],&src->options[i],sizeof(cups_option_t));
+ if(src->options[i].name!=NULL) dst->options[i].name=strdup(src->options[i].name);
+ if(src->options[i].value!=NULL) dst->options[i].value=strdup(src->options[i].value);
+ }
+ return(dst);
+}
+
MODULE = Net::CUPS PACKAGE = Net::CUPS
PROTOTYPES: DISABLE
@@ -134,9 +149,11 @@
for( loop = 0; loop < count; loop++ )
{
rv = sv_newmortal();
- sv_setref_pv( rv, "Net::CUPS::Destination", &destinations[loop] );
+ cups_dest_t *single=cupsCloneDest(&destinations[loop]);
+ sv_setref_pv( rv, "Net::CUPS::Destination", single );
XPUSHs( rv );
}
+ cupsFreeDests(count,destinations);
XSRETURN( count );
ppd_file_t*