From: Peter Pentchev Date: Tue, 9 Jun 2009 14:24:06 +0000 (+0000) Subject: Merge trunk rev. 3769: аctually *use* the mailname cache and X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=2f4bc421bae2d48c34385bad5937bfb06ebf413a;p=people%2Fms%2Fdma.git Merge trunk rev. 3769: аctually *use* the mailname cache and fix a file descriptor leak. --- diff --git a/patches/17-mailname.patch b/patches/17-mailname.patch index fdc4ac6..437f2d7 100644 --- a/patches/17-mailname.patch +++ b/patches/17-mailname.patch @@ -43,18 +43,18 @@ For Debian, use /etc/mailname for the MAILNAMEFILE. The --- a/dma.c +++ b/dma.c -@@ -82,10 +82,38 @@ +@@ -83,10 +83,40 @@ hostname(void) { static char name[MAXHOSTNAMELEN+1]; -- -+ int initialized = 0; ++ static int initialized = 0; + FILE *fp; ++ char *res; + size_t len; + + if (initialized) + return (name); -+ + + if (config->mailname != NULL && config->mailname[0] != '\0') { + snprintf(name, sizeof(name), "%s", config->mailname); + initialized = 1; @@ -63,7 +63,9 @@ For Debian, use /etc/mailname for the MAILNAMEFILE. + if (config->mailnamefile != NULL && config->mailnamefile[0] != '\0') { + fp = fopen(config->mailnamefile, "r"); + if (fp != NULL) { -+ if (fgets(name, sizeof(name), fp) != NULL) { ++ res = fgets(name, sizeof(name), fp); ++ fclose(fp); ++ if (res != NULL) { + len = strlen(name); + while (len > 0 && + (name[len - 1] == '\r' || @@ -74,7 +76,6 @@ For Debian, use /etc/mailname for the MAILNAMEFILE. + return (name); + } + } -+ fclose(fp); + } + } if (gethostname(name, sizeof(name)) != 0)