summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortsi <tsi>2008-01-01 02:02:34 +0000
committertsi <tsi>2008-01-01 02:02:34 +0000
commit39c0b36a5fa157cbe9b33b9557e680c94c934ce0 (patch)
tree4d061f87a9a82667f4a2a2dc93a0a1d8148430d3
parent65faad0d3f9c0e2315fdeadc7bced17caab93f63 (diff)
16. Fix file descriptor leaks in Xprt, and various attempts to close streams
that were not opened successfully (Marc La France).
-rw-r--r--programs/Xserver/Xprint/Init.c89
-rw-r--r--programs/Xserver/Xprint/ps/PsPrint.c11
-rw-r--r--programs/Xserver/Xprint/ps/PsText.c7
-rw-r--r--programs/Xserver/hw/xfree86/CHANGELOG4
4 files changed, 63 insertions, 48 deletions
diff --git a/programs/Xserver/Xprint/Init.c b/programs/Xserver/Xprint/Init.c
index c632d3402..3b2f6a4d4 100644
--- a/programs/Xserver/Xprint/Init.c
+++ b/programs/Xserver/Xprint/Init.c
@@ -1,4 +1,4 @@
-/* $XFree86: xc/programs/Xserver/Xprint/Init.c,v 1.18tsi Exp $ */
+/* $XFree86: xc/programs/Xserver/Xprint/Init.c,v 1.19tsi Exp $ */
/*
(c) Copyright 1996 Hewlett-Packard Company
(c) Copyright 1996 International Business Machines Corp.
@@ -716,53 +716,66 @@ BuildPrinterDb(void)
char line[256];
FILE *fp = fopen(configFileName, "r");
- while(fgets(line, 256, fp) != (char *)NULL)
+ if(!fp)
{
- char *tok, *ptr;
- if((tok = strtok(line, " \t\012")) != (char *)NULL)
+ ErrorF("Xp Extension: Can't open file %s\n", configFileName);
+ configFileName = (char *)NULL;
+ }
+ else
+ {
+ while(fgets(line, 256, fp) != (char *)NULL)
{
- if(tok[0] == (char)'#') continue;
- if(strcmp(tok, "Printer") == 0)
+ char *tok, *ptr;
+ if((tok = strtok(line, " \t\012")) != (char *)NULL)
{
- while((tok = strtok((char *)NULL, " \t")) != (char *)NULL)
+ if(tok[0] == (char)'#')
+ continue;
+ if(strcmp(tok, "Printer") == 0)
{
- if ((ptr = MbStrchr(tok, '\012')) != 0)
- *ptr = (char)'\0';
- AddPrinterDbName(tok);
+ while((tok = strtok((char *)NULL, " \t")) !=
+ (char *)NULL)
+ {
+ if ((ptr = MbStrchr(tok, '\012')) != 0)
+ *ptr = (char)'\0';
+ AddPrinterDbName(tok);
+ }
}
- }
- else if(strcmp(tok, "Map") == 0)
- {
- char *name, *qualifier;
-
- if((tok = strtok((char *)NULL, " \t\012")) == (char *)NULL)
- continue;
- name = strdup(tok);
- if((tok = strtok((char *)NULL, " \t\012")) == (char *)NULL)
+ else if(strcmp(tok, "Map") == 0)
{
- xfree(name);
- continue;
+ char *name, *qualifier;
+
+ if((tok = strtok((char *)NULL, " \t\012")) ==
+ (char *)NULL)
+ continue;
+ name = strdup(tok);
+ if((tok = strtok((char *)NULL, " \t\012")) ==
+ (char *)NULL)
+ {
+ xfree(name);
+ continue;
+ }
+ qualifier = strdup(tok);
+ AddNameMap(name, qualifier);
}
- qualifier = strdup(tok);
- AddNameMap(name, qualifier);
- }
- else if(strcmp(tok, "Augment_Printer_List") == 0)
- {
- if((tok = strtok((char *)NULL, " \t\012")) == (char *)NULL)
- continue;
-
- if(strcmp(tok, "%default%") == 0)
- continue;
- defaultAugment = FALSE;
- if(strcmp(tok, "%none%") == 0)
- continue;
- AugmentPrinterDb(tok);
+ else if(strcmp(tok, "Augment_Printer_List") == 0)
+ {
+ if((tok = strtok((char *)NULL, " \t\012")) ==
+ (char *)NULL)
+ continue;
+
+ if(strcmp(tok, "%default%") == 0)
+ continue;
+ defaultAugment = FALSE;
+ if(strcmp(tok, "%none%") == 0)
+ continue;
+ AugmentPrinterDb(tok);
+ }
+ else
+ break; /* XXX Generate an error? */
}
- else
- break; /* XXX Generate an error? */
}
+ fclose(fp);
}
- fclose(fp);
}
if(defaultAugment == TRUE)
diff --git a/programs/Xserver/Xprint/ps/PsPrint.c b/programs/Xserver/Xprint/ps/PsPrint.c
index 087b7db0c..d8ba05cf7 100644
--- a/programs/Xserver/Xprint/ps/PsPrint.c
+++ b/programs/Xserver/Xprint/ps/PsPrint.c
@@ -1,4 +1,4 @@
-/* $XFree86: xc/programs/Xserver/Xprint/ps/PsPrint.c,v 1.11tsi Exp $ */
+/* $XFree86: xc/programs/Xserver/Xprint/ps/PsPrint.c,v 1.12tsi Exp $ */
/*
Copyright 1996, 1998 The Open Group
@@ -241,13 +241,16 @@ PsEndJob(
FILE *file;
file = fopen(priv->jobFileName, "r");
- if (!file || (fstat(fileno(file), &buffer) < 0))
+ if (!file)
r = BadAlloc;
- else
+ else if (fstat(fileno(file), &buffer) < 0) {
+ fclose(file);
+ r = BadAlloc;
+ } else {
r = XpSendDocumentData(priv->getDocClient, file, buffer.st_size,
priv->getDocBufSize);
- if (file)
fclose(file);
+ }
(void) XpFinishDocData(priv->getDocClient);
diff --git a/programs/Xserver/Xprint/ps/PsText.c b/programs/Xserver/Xprint/ps/PsText.c
index 17aaf6dc7..245df18d8 100644
--- a/programs/Xserver/Xprint/ps/PsText.c
+++ b/programs/Xserver/Xprint/ps/PsText.c
@@ -1,3 +1,4 @@
+/* $XFree86: xc/programs/Xserver/Xprint/ps/PsText.c,v 1.14tsi Exp $ */
/*
Copyright 1996, 1998 The Open Group
@@ -72,7 +73,6 @@ in this Software without prior written authorization from The Open Group.
** *********************************************************
**
********************************************************************/
-/* $XFree86: xc/programs/Xserver/Xprint/ps/PsText.c,v 1.13 2003/10/29 22:11:55 tsi Exp $ */
#include "Ps.h"
#include "gcstruct.h"
@@ -83,15 +83,12 @@ in this Software without prior written authorization from The Open Group.
static int readFontName(char *fileName, char *file_name, char *dlfnam)
{
FILE *file;
- struct stat statb;
char buf[256];
char *front, *fn;
file = fopen(fileName, "r");
if(file)
{
- if (fstat (fileno(file), &statb) == -1)
- return 0;
while(fgets(buf, 255, file))
{
if((fn = strstr(buf, " -")))
@@ -110,9 +107,9 @@ static int readFontName(char *fileName, char *file_name, char *dlfnam)
}
}
}
+ fclose(file);
}
file_name[0] = '\0';
- fclose(file);
return 0;
}
diff --git a/programs/Xserver/hw/xfree86/CHANGELOG b/programs/Xserver/hw/xfree86/CHANGELOG
index 3abd31e42..7eb7f0beb 100644
--- a/programs/Xserver/hw/xfree86/CHANGELOG
+++ b/programs/Xserver/hw/xfree86/CHANGELOG
@@ -1,4 +1,6 @@
XFree86 4.7.99.9 (xx January 2008)
+ 16. Fix file descriptor leaks in Xprt, and various attempts to close streams
+ that were not opened successfully (Marc La France).
XFree86 4.7.99.8 (23 December 2007)
@@ -20636,4 +20638,4 @@ XFree86 3.0a (28 April 1994)
XFree86 3.0 (26 April 1994)
-$XFree86: xc/programs/Xserver/hw/xfree86/CHANGELOG,v 3.3923 2007/12/09 12:03:09 dawes Exp $
+$XFree86: xc/programs/Xserver/hw/xfree86/CHANGELOG,v 3.3924 2007/12/23 12:02:57 dawes Exp $