Explorar o código

ensure that we fclose/unlink/free in the new gpg-code as soon as possible

David Kalnischkies %!s(int64=13) %!d(string=hai) anos
pai
achega
bea263c2c0
Modificáronse 1 ficheiros con 22 adicións e 5 borrados
  1. 22 5
      apt-pkg/contrib/gpgv.cc

+ 22 - 5
apt-pkg/contrib/gpgv.cc

@@ -214,19 +214,25 @@ void ExecGPGV(std::string const &File, std::string const &FileGPG,
 	 ioprintf(std::cerr, _("Waited for %s but it wasn't there"), "gpgv");
 	 ioprintf(std::cerr, _("Waited for %s but it wasn't there"), "gpgv");
 	 UNLINK_EXIT(EINTERNAL);
 	 UNLINK_EXIT(EINTERNAL);
       }
       }
+#undef UNLINK_EXIT
+      // we don't need the files any longer as we have the filedescriptors still open
+      unlink(sig);
+      unlink(data);
+      free(sig);
+      free(data);
 
 
       // check if it exit'ed normally …
       // check if it exit'ed normally …
       if (WIFEXITED(Status) == false)
       if (WIFEXITED(Status) == false)
       {
       {
 	 ioprintf(std::cerr, _("Sub-process %s exited unexpectedly"), "gpgv");
 	 ioprintf(std::cerr, _("Sub-process %s exited unexpectedly"), "gpgv");
-	 UNLINK_EXIT(EINTERNAL);
+	 exit(EINTERNAL);
       }
       }
 
 
       // … and with a good exit code
       // … and with a good exit code
       if (WEXITSTATUS(Status) != 0)
       if (WEXITSTATUS(Status) != 0)
       {
       {
 	 ioprintf(std::cerr, _("Sub-process %s returned an error code (%u)"), "gpgv", WEXITSTATUS(Status));
 	 ioprintf(std::cerr, _("Sub-process %s returned an error code (%u)"), "gpgv", WEXITSTATUS(Status));
-	 UNLINK_EXIT(WEXITSTATUS(Status));
+	 exit(WEXITSTATUS(Status));
       }
       }
 
 
       /* looks like its fine. Our caller will check the status fd,
       /* looks like its fine. Our caller will check the status fd,
@@ -236,12 +242,11 @@ void ExecGPGV(std::string const &File, std::string const &FileGPG,
       if (RecombineToClearSignedFile(File, dataFd, dataHeader, sigFd) == false)
       if (RecombineToClearSignedFile(File, dataFd, dataHeader, sigFd) == false)
       {
       {
 	 _error->DumpErrors(std::cerr);
 	 _error->DumpErrors(std::cerr);
-	 UNLINK_EXIT(EINTERNAL);
+	 exit(EINTERNAL);
       }
       }
 
 
       // everything fine, we have a clean file now!
       // everything fine, we have a clean file now!
-      UNLINK_EXIT(0);
-#undef UNLINK_EXIT
+      exit(0);
    }
    }
    exit(EINTERNAL); // unreachable safe-guard
    exit(EINTERNAL); // unreachable safe-guard
 }
 }
@@ -259,7 +264,10 @@ bool RecombineToClearSignedFile(std::string const &OutFile, int const ContentFil
    FILE *data_file = fdopen(ContentFile, "r");
    FILE *data_file = fdopen(ContentFile, "r");
    FILE *sig_file = fdopen(SignatureFile, "r");
    FILE *sig_file = fdopen(SignatureFile, "r");
    if (data_file == NULL || sig_file == NULL)
    if (data_file == NULL || sig_file == NULL)
+   {
+      fclose(clean_file);
       return _error->Error("Couldn't open splitfiles to recombine them into %s", OutFile.c_str());
       return _error->Error("Couldn't open splitfiles to recombine them into %s", OutFile.c_str());
+   }
    char *buf = NULL;
    char *buf = NULL;
    size_t buf_size = 0;
    size_t buf_size = 0;
    while (getline(&buf, &buf_size, data_file) != -1)
    while (getline(&buf, &buf_size, data_file) != -1)
@@ -287,13 +295,21 @@ bool SplitClearSignedFile(std::string const &InFile, int const ContentFile,
    {
    {
       out_content = fdopen(ContentFile, "w");
       out_content = fdopen(ContentFile, "w");
       if (out_content == NULL)
       if (out_content == NULL)
+      {
+	 fclose(in);
 	 return _error->Errno("fdopen", "Failed to open file to write content to from %s", InFile.c_str());
 	 return _error->Errno("fdopen", "Failed to open file to write content to from %s", InFile.c_str());
+      }
    }
    }
    if (SignatureFile != -1)
    if (SignatureFile != -1)
    {
    {
       out_signature = fdopen(SignatureFile, "w");
       out_signature = fdopen(SignatureFile, "w");
       if (out_signature == NULL)
       if (out_signature == NULL)
+      {
+	 fclose(in);
+	 if (out_content != NULL)
+	    fclose(out_content);
 	 return _error->Errno("fdopen", "Failed to open file to write signature to from %s", InFile.c_str());
 	 return _error->Errno("fdopen", "Failed to open file to write signature to from %s", InFile.c_str());
+      }
    }
    }
 
 
    bool found_message_start = false;
    bool found_message_start = false;
@@ -358,6 +374,7 @@ bool SplitClearSignedFile(std::string const &InFile, int const ContentFile,
       fclose(out_content);
       fclose(out_content);
    if (out_signature != NULL)
    if (out_signature != NULL)
       fclose(out_signature);
       fclose(out_signature);
+   fclose(in);
 
 
    return true;
    return true;
 }
 }