summaryrefslogtreecommitdiff
path: root/test/interactive-helper
diff options
context:
space:
mode:
authorDavid Kalnischkies <david@kalnischkies.de>2016-06-09 21:06:48 +0200
committerJulian Andres Klode <jak@debian.org>2016-06-10 15:25:19 +0200
commit49997ef025ee454283722a01210c169ca8910a98 (patch)
tree58f2355cc6aacdfa0b3a375e545b3ec74d853086 /test/interactive-helper
parent36feef0dc51c444de1449ba26a0bf2248716591d (diff)
don't leak an FD in lz4 (de)compression
Seen first in #826783, but as this buglog also shows leaked uncompressed files as well we don't close it just yet. (cherry picked from commit 6f35be91c9e86e463bca7df6eadf05412c7b732c)
Diffstat (limited to 'test/interactive-helper')
-rw-r--r--test/interactive-helper/makefile6
-rw-r--r--test/interactive-helper/test_fileutl.cc43
2 files changed, 49 insertions, 0 deletions
diff --git a/test/interactive-helper/makefile b/test/interactive-helper/makefile
index 4633b78ce..096767c41 100644
--- a/test/interactive-helper/makefile
+++ b/test/interactive-helper/makefile
@@ -33,6 +33,12 @@ LIB_MAKES = apt-pkg/makefile
SOURCE = test_udevcdrom.cc
include $(PROGRAM_H)
+PROGRAM=test_fileutl
+SLIBS = -lapt-pkg
+LIB_MAKES = apt-pkg/makefile
+SOURCE = test_fileutl.cc
+include $(PROGRAM_H)
+
# Program for checking rpm versions
#PROGRAM=rpmver
#SLIBS = -lapt-pkg -lrpm
diff --git a/test/interactive-helper/test_fileutl.cc b/test/interactive-helper/test_fileutl.cc
new file mode 100644
index 000000000..e660c2981
--- /dev/null
+++ b/test/interactive-helper/test_fileutl.cc
@@ -0,0 +1,43 @@
+#include <apt-pkg/fileutl.h>
+#include <apt-pkg/strutl.h>
+#include <apt-pkg/error.h>
+
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <unistd.h>
+#include <stdlib.h>
+#include <fcntl.h>
+
+#include <iostream>
+#include <string>
+
+static void callsystem(std::string const &call)
+{
+ auto ret = system(call.c_str());
+ if (WIFEXITED(ret) == false || WEXITSTATUS(ret) != 0)
+ _error->Error("Calling %s failed!", call.c_str());
+}
+
+int main(int, char ** argv)
+{
+ auto const pid = getpid();
+ std::string ls;
+ strprintf(ls, "ls -l /proc/%d/fd", pid);
+ callsystem(ls);
+ FileFd t;
+ t.Open(argv[1], FileFd::ReadOnly, FileFd::Extension);
+ callsystem(ls);
+ char buf[1024];
+ unsigned long long act;
+ while (t.Read(buf, sizeof(buf), &act))
+ if (act == 0)
+ break;
+ callsystem(ls);
+ t.Seek(5);
+ callsystem(ls);
+ t.Close();
+ callsystem(ls);
+ auto const ret = _error->PendingError();
+ _error->DumpErrors();
+ return ret;
+}