Remove unused variable and check return codes
@@ -193,7 +193,11 @@ static rdpPrinter* printer_win_new_printer(rdpWinPrinterDriver* win_driver,
return NULL;
win_printer->printer.id = win_driver->id_sequence++;
- ConvertFromUnicode(CP_UTF8, 0, name, -1, &win_printer->printer.name, 0, NULL, NULL);
+ if (ConvertFromUnicode(CP_UTF8, 0, name, -1, &win_printer->printer.name, 0, NULL, NULL) < 1)
+ {
+ free(win_printer);
+ return NULL;
+ }
if (!win_printer->printer.name)
{
@@ -206,9 +210,20 @@ static rdpPrinter* printer_win_new_printer(rdpWinPrinterDriver* win_driver,
win_printer->printer.FindPrintJob = printer_win_find_printjob;
win_printer->printer.Free = printer_win_free_printer;
- OpenPrinter(name, &(win_printer->hPrinter), NULL);
+ if (!OpenPrinter(name, &(win_printer->hPrinter), NULL))
+ {
+ free(win_printer->printer.name);
+ free(win_printer);
+ return NULL;
+ }
+
+ if (!GetPrinter(win_printer->hPrinter, 2, (LPBYTE) prninfo, 0, &needed))
+ {
+ free(win_printer->printer.name);
+ free(win_printer);
+ return NULL;
+ }
- GetPrinter(win_printer->hPrinter, 2, (LPBYTE) prninfo, 0, &needed);
prninfo = (PRINTER_INFO_2*) GlobalAlloc(GPTR,needed);
if (!prninfo)
{
@@ -216,7 +231,14 @@ static rdpPrinter* printer_win_new_printer(rdpWinPrinterDriver* win_driver,
free(win_printer);
return NULL;
}
- GetPrinter(win_printer->hPrinter, 2, (LPBYTE) prninfo, needed, &needed);
+
+ if (!GetPrinter(win_printer->hPrinter, 2, (LPBYTE) prninfo, needed, &needed))
+ {
+ GlobalFree(prninfo);
+ free(win_printer->printer.name);
+ free(win_printer);
+ return NULL;
+ }
if (drivername)
status = ConvertFromUnicode(CP_UTF8, 0, drivername, -1, &win_printer->printer.driver, 0, NULL, NULL);
@@ -238,7 +260,6 @@ static rdpPrinter** printer_win_enum_printers(rdpPrinterDriver* driver)
rdpPrinter** printers;
int num_printers;
int i;
- char* pname = NULL;
PRINTER_INFO_2* prninfo = NULL;
DWORD needed, returned;
