I think there is a small memory leak with this code :
https://www.cups.org/documentation.php/doc-2.0/api-cups.html#cupsGetDests

"Use the cupsFreeDests function to free the destination list"

Also I am not sure if you are using cupsGetDest as intended :-

 202     cups_dest_t *dest = j2d_cupsGetDest(NULL, NULL, num_dests, dests);
 203     if (dest != NULL) {
 204         for (i = 0; i < num_dests; i++) {
 205             if (dest[i].is_default) {
 206                 defaultPrinter = dest[i].name;
 207                 break;
 208             }
 209         }
 210     }


I don't think you are expected to iterate over the result here.
I think it is already the pointer to the default. In other words
the function will already have done what your for loop is doing.
If there is no default you will iterate off the end ..

-phil.

On 03/03/2016 02:39 AM, prasanta sadhukhan wrote:
Hi Phil,

Bug: https://bugs.openjdk.java.net/browse/JDK-8058316
webrev: http://cr.openjdk.java.net/~psadhukhan/8058316/webrev.00/

The issue was on some Solaris 11 hosts lookupDefaultPrintService() returns null while lpstat -d reports an ipp printer.
The issue was found to exist in linux too since it uses CUPS.

What was happening was that CUPSPrinter.java#getDefaultPrinter() searches for server-defined default destination by connection to CUPS server but if the user sets the default printer using "lpoptions -d <printername>" command, server will not have any knowledge of this settings and this user-set default printer (which is stored in ~/.cups/lpoptions file) was not searched and getDefaultPrinter() returns null since it could not find any server default printer.

Fix is to call cupsGetDest API to search for a lpoptions-defined default printer and if not set, then search for server-defined destination.

I could not provide a regression testcase for this as it involves setting default printer using lpoptions command.

Regards
Prasanta


Reply via email to