]> git.ipfire.org Git - people/ms/dma.git/commitdiff
Merge trunk rev. 3769: аctually *use* the mailname cache and
authorPeter Pentchev <roam@ringlet.net>
Tue, 9 Jun 2009 14:24:06 +0000 (14:24 +0000)
committerPeter Pentchev <roam@ringlet.net>
Tue, 9 Jun 2009 14:24:06 +0000 (14:24 +0000)
fix a file descriptor leak.

patches/17-mailname.patch

index fdc4ac606ca49f8484ae6be9eb148bb68a92685b..437f2d7b09f4a8b638418f8dbebef8d940ae318e 100644 (file)
@@ -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)