From 5ed9a986984a7ffe34663fab049f2ac4903a0f58 Mon Sep 17 00:00:00 2001 From: Sebastien Pouliot Date: Fri, 9 Feb 2007 14:19:48 +0000 Subject: [PATCH] 2007-02-09 Sebastien Pouliot * PrintingServicesUnix.cs: Ensure we free the original pointer in GetAlternativeDefaultPrinter (not the one used for iteration). svn path=/trunk/mcs/; revision=72542 --- .../System.Drawing.Printing/ChangeLog | 5 +++ .../PrintingServicesUnix.cs | 33 ++++++++++--------- 2 files changed, 23 insertions(+), 15 deletions(-) diff --git a/mcs/class/System.Drawing/System.Drawing.Printing/ChangeLog b/mcs/class/System.Drawing/System.Drawing.Printing/ChangeLog index 1a2d5ddb38f..9d19750b7d2 100644 --- a/mcs/class/System.Drawing/System.Drawing.Printing/ChangeLog +++ b/mcs/class/System.Drawing/System.Drawing.Printing/ChangeLog @@ -1,3 +1,8 @@ +2007-02-09 Sebastien Pouliot + + * PrintingServicesUnix.cs: Ensure we free the original pointer in + GetAlternativeDefaultPrinter (not the one used for iteration). + 2007-01-19 Andreia Gaita * PrintingServicesUnix.cs: Add is_default flag check for diff --git a/mcs/class/System.Drawing/System.Drawing.Printing/PrintingServicesUnix.cs b/mcs/class/System.Drawing/System.Drawing.Printing/PrintingServicesUnix.cs index 64c3f8d04d2..bc7e4259d32 100644 --- a/mcs/class/System.Drawing/System.Drawing.Printing/PrintingServicesUnix.cs +++ b/mcs/class/System.Drawing/System.Drawing.Printing/PrintingServicesUnix.cs @@ -1,5 +1,5 @@ // -// Copyright (C) 2005 Novell, Inc. http://www.novell.com +// Copyright (C) 2005, 2007 Novell, Inc. http://www.novell.com // // Permission is hereby granted, free of charge, to any person obtaining // a copy of this software and associated documentation files (the @@ -362,26 +362,29 @@ namespace System.Drawing.Printing /// returns the first one. See #80519, #80198 /// /// - private string GetAlternativeDefaultPrinter() { + private string GetAlternativeDefaultPrinter () + { IntPtr printers = IntPtr.Zero; - CUPS_DESTS printer; string printer_name = String.Empty; - int cups_dests_size = Marshal.SizeOf(typeof(CUPS_DESTS)); - int printer_count = cupsGetDests (ref printers); - - for (int i = 0; i < printer_count; i++) { - printer = (CUPS_DESTS) Marshal.PtrToStructure (printers, typeof (CUPS_DESTS)); - - if (printer.is_default != 0 || printer_name.Equals(String.Empty)) { - printer_name = Marshal.PtrToStringAnsi (printer.name); - if (printer.is_default != 0) - break; + try { + int cups_dests_size = Marshal.SizeOf (typeof (CUPS_DESTS)); + IntPtr current = printers; + for (int i = 0; i < printer_count; i++) { + CUPS_DESTS printer = (CUPS_DESTS) Marshal.PtrToStructure (current, typeof (CUPS_DESTS)); + + if ((printer.is_default != 0) || (printer_name.Length == 0)) { + printer_name = Marshal.PtrToStringAnsi (printer.name); + if (printer.is_default != 0) + break; + } + current = new IntPtr (current.ToInt64 () + cups_dests_size); } - printers = new IntPtr (printers.ToInt64 () + cups_dests_size); } - Marshal.FreeHGlobal (printers); + finally { + Marshal.FreeHGlobal (printers); + } return printer_name; } -- 2.25.1