[Libreoffice-commits] online.git: common/FileUtil.cpp common/FileUtil.hpp test/helpers.hpp

Ashod Nakashian (via logerrit) logerrit at kemper.freedesktop.org
Mon Nov 18 05:47:39 UTC 2019


 common/FileUtil.cpp |   10 ++++------
 common/FileUtil.hpp |   12 ++++++++----
 test/helpers.hpp    |   13 +++++++++----
 3 files changed, 21 insertions(+), 14 deletions(-)

New commits:
commit 1ae9ce8ad29585e42c6ea0ab924080855f14d0f6
Author:     Ashod Nakashian <ashod.nakashian at collabora.co.uk>
AuthorDate: Sun Nov 17 20:32:54 2019 -0500
Commit:     Michael Meeks <michael.meeks at collabora.com>
CommitDate: Mon Nov 18 06:47:20 2019 +0100

    test: thread-safe common shared test data
    
    This protects against memory corruptions,
    and a cascade of issues, such as the following:
    
     Attaching to process 56245
     [New LWP 56246]
     [New LWP 56252]
     [New LWP 56253]
     [New LWP 56254]
     [New LWP 56362]
     [New LWP 56364]
     [Thread debugging using libthread_db enabled]
     Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".
     0x00007fda228f7d2d in __GI___pthread_timedjoin_ex (threadid=140574279595776, thread_return=0x0, abstime=0x0, block=<optimized out>) at pthread_join_common.c:89
     89     pthread_join_common.c: No such file or directory.
    
     Thread 7 (Thread 0x7fda197fa700 (LWP 56364)):
     #0  __lll_lock_wait () at ../sysdeps/unix/sysv/linux/x86_64/lowlevellock.S:135
     #1  0x00007fda228f9023 in __GI___pthread_mutex_lock (mutex=0x55e9937567e0 <SigHandlerTrap>) at ../nptl/pthread_mutex_lock.c:78
     #2  0x000055e9934cd4fe in __gthread_mutex_lock (__mutex=0x55e9937567e0 <SigHandlerTrap>) at /usr/include/x86_64-linux-gnu/c++/7/bits/gthr-default.h:748
     #3  std::mutex::lock (this=0x55e9937567e0 <SigHandlerTrap>) at /usr/include/c++/7/bits/std_mutex.h:103
     #4  std::unique_lock<std::mutex>::lock (this=<synthetic pointer>) at /usr/include/c++/7/bits/std_mutex.h:267
     #5  std::unique_lock<std::mutex>::unique_lock (__m=..., this=<synthetic pointer>) at /usr/include/c++/7/bits/std_mutex.h:197
     #6  SigUtil::handleFatalSignal (signal=11) at common/SigUtil.cpp:214
     #7  <signal handler called>
     #8  std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::_M_capacity (this=<optimized out>, __capacity=0) at /usr/include/c++/7/bits/basic_string.h:200
     #9  std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::basic_string (__str=..., this=<optimized out>) at /usr/include/c++/7/bits/basic_string.h:542
     #10 std::_Construct<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > (
         __p=<optimized out>) at /usr/include/c++/7/bits/stl_construct.h:75
     #11 std::__uninitialized_copy<false>::__uninit_copy<std::move_iterator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >*>, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >*> (__result=0x7fd9f40017b0, __last=..., __first=...) at /usr/include/c++/7/bits/stl_uninitialized.h:83
     #12 std::uninitialized_copy<std::move_iterator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >*>, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >*> (__result=<optimized out>, __last=..., __first=...) at /usr/include/c++/7/bits/stl_uninitialized.h:134
     #13 std::__uninitialized_copy_a<std::move_iterator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >*>, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >*, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > (__result=<optimized out>, __last=..., __first=...)
         at /usr/include/c++/7/bits/stl_uninitialized.h:289
     #14 std::__uninitialized_move_if_noexcept_a<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >*, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >*, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > > (__alloc=..., __result=<optimized out>, __last=0x55e995662850,
         __first=<optimized out>) at /usr/include/c++/7/bits/stl_uninitialized.h:312
     #15 std::vector<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > >::_M_realloc_insert<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&> (
         this=this at entry=0x55e9937566f0 <FileUtil::getTempFilePath(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)::fileDeleter>,
         __position=<error: Cannot access memory at address 0x3735003238323a>, __args#0="/tmp/loadTorture_viewcursor.odp_725a6013_viewcursor.odp") at /usr/include/c++/7/bits/vector.tcc:424
     #16 0x000055e9934aa829 in std::vector<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > >::push_back (__x="/tmp/loadTorture_viewcursor.odp_725a6013_viewcursor.odp",
         this=0x55e9937566f0 <FileUtil::getTempFilePath(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)::fileDeleter>) at /usr/include/c++/7/bits/stl_vector.h:948
     #17 (anonymous namespace)::FileDeleter::registerForDeletion (file="/tmp/loadTorture_viewcursor.odp_725a6013_viewcursor.odp",
         this=0x55e9937566f0 <FileUtil::getTempFilePath(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)::fileDeleter>) at common/FileUtil.cpp:69
     #18 FileUtil::getTempFilePath (srcDir=..., srcFilename=..., dstFilenamePrefix=...) at common/FileUtil.cpp:97
     #19 0x00007fda216b51c9 in helpers::getDocumentPathAndURL (docFilename="viewcursor.odp", documentPath="", documentURL="", prefix="loadTorture_viewcursor.odp_") at ./helpers.hpp:151
     #20 0x00007fda216ad007 in UnitLoadTorture::loadTorture (this=<optimized out>, testname="loadTorture_viewcursor.odp ", docName="viewcursor.odp", thread_count=thread_count at entry=3,
         max_jitter_ms=<optimized out>, max_jitter_ms at entry=75) at UnitLoadTorture.cpp:41
     #21 0x00007fda216ad7dd in UnitLoadTorture::<lambda()>::operator() (__closure=0x55e994dbc758) at UnitLoadTorture.cpp:186
     #22 std::__invoke_impl<void, UnitLoadTorture::testLoadTorture()::<lambda()> > (__f=...) at /usr/include/c++/7/bits/invoke.h:60
     #23 std::__invoke<UnitLoadTorture::testLoadTorture()::<lambda()> > (__fn=...) at /usr/include/c++/7/bits/invoke.h:95
     #24 std::thread::_Invoker<std::tuple<UnitLoadTorture::testLoadTorture()::<lambda()> > >::_M_invoke<0> (this=0x55e994dbc758) at /usr/include/c++/7/thread:234
     #25 std::thread::_Invoker<std::tuple<UnitLoadTorture::testLoadTorture()::<lambda()> > >::operator() (this=0x55e994dbc758) at /usr/include/c++/7/thread:243
     #26 std::thread::_State_impl<std::thread::_Invoker<std::tuple<UnitLoadTorture::testLoadTorture()::<lambda()> > > >::_M_run(void) (this=0x55e994dbc750) at /usr/include/c++/7/thread:186
     #27 0x00007fda22de366f in ?? () from /usr/lib/x86_64-linux-gnu/libstdc++.so.6
     #28 0x00007fda228f66db in start_thread (arg=0x7fda197fa700) at pthread_create.c:463
     #29 0x00007fda2261f88f in clone () at ../sysdeps/unix/sysv/linux/x86_64/clone.S:95
    
     Thread 6 (Thread 0x7fd9fffff700 (LWP 56362)):
      #0  __lll_lock_wait_private () at ../sysdeps/unix/sysv/linux/x86_64/lowlevellock.S:95
     #1  0x00007fda225952db in __GI___libc_malloc (bytes=bytes at entry=3635) at malloc.c:3063
     #2  0x00007fda2262f364 in __backtrace_symbols (array=array at entry=0x7fd9ffffc540, size=size at entry=26) at backtracesyms.c:69
     #3  0x000055e9934cc439 in SigUtil::dumpBacktrace () at common/SigUtil.cpp:253
     #4  0x000055e9934cd5ae in SigUtil::handleFatalSignal (signal=6) at common/SigUtil.cpp:236
     #5  <signal handler called>
     #6  __GI_raise (sig=sig at entry=6) at ../sysdeps/unix/sysv/linux/raise.c:51
     #7  0x00007fda2253e801 in __GI_abort () at abort.c:79
     #8  0x00007fda22587897 in __libc_message (action=action at entry=do_abort, fmt=fmt at entry=0x7fda226b4b9a "%s
    ") at ../sysdeps/posix/libc_fatal.c:181
     #9  0x00007fda2258e90a in malloc_printerr (str=str at entry=0x7fda226b2e0e "malloc(): memory corruption") at malloc.c:5350
     #10 0x00007fda22592994 in _int_malloc (av=av at entry=0x7fda00000020, bytes=bytes at entry=32) at malloc.c:3738
     #11 0x00007fda225952ed in __GI___libc_malloc (bytes=32) at malloc.c:3065
     #12 0x00007fda22db9258 in operator new(unsigned long) () from /usr/lib/x86_64-linux-gnu/libstdc++.so.6
     #13 0x00007fda244adaae in __gnu_cxx::new_allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >::allocate (this=0x7fd9ffffe740, __n=1)
         at /usr/include/c++/5/ext/new_allocator.h:104
     #14 0x00007fda244ad300 in __gnu_cxx::__alloc_traits<std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > >::allocate (__a=..., __n=1)
         at /usr/include/c++/5/ext/alloc_traits.h:182
     #15 0x00007fda244ac858 in std::_Vector_base<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > >::_M_allocate (this=0x7fd9ffffe740, __n=1) at /usr/include/c++/5/bits/stl_vector.h:170
     #16 0x00007fda244ab7c7 in std::vector<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > >::_M_insert_aux (this=0x7fd9ffffe740, __position=non-dereferenceable iterator for std::vector, __x="home") at /usr/include/c++/5/bits/vector.tcc:353
     #17 0x00007fda244aada2 in std::vector<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > >::push_back (this=0x7fd9ffffe740, __x="home") at /usr/include/c++/5/bits/stl_vector.h:925
     #18 0x00007fda2350ddcb in Poco::Path::pushDirectory (this=0x7fd9ffffe6c0, dir="home") at src/Path.cpp:471
     #19 0x00007fda2350ea27 in Poco::Path::parseUnix (this=0x7fd9ffffe6c0, path="/home/ash/prj/lo/online/test/") at src/Path.cpp:671
     #20 0x00007fda2350cd6b in Poco::Path::assign (this=0x7fd9ffffe6c0, path="/home/ash/prj/lo/online/test/") at src/Path.cpp:182
     #21 0x00007fda2350c1be in Poco::Path::Path (this=0x7fd9ffffe6c0, path="/home/ash/prj/lo/online/test/") at src/Path.cpp:54
     #22 0x00007fda2350d33a in Poco::Path::makeAbsolute (this=0x7fd9ffffe8f0) at src/Path.cpp:318
     #23 0x00007fda216b52ca in helpers::getDocumentPathAndURL (docFilename="setclientpart.ods", documentPath="/tmp/loadTorture_setclientpart.ods_ae70d2e_setclientpart.ods", documentURL="",
         prefix="loadTorture_setclientpart.ods_") at ./helpers.hpp:153
     #24 0x00007fda216ad007 in UnitLoadTorture::loadTorture (this=<optimized out>, testname="loadTorture_setclientpart.ods ", docName="setclientpart.ods", thread_count=thread_count at entry=3,
         max_jitter_ms=<optimized out>, max_jitter_ms at entry=75) at UnitLoadTorture.cpp:41
     #25 0x00007fda216ad7dd in UnitLoadTorture::<lambda()>::operator() (__closure=0x55e994cffe18) at UnitLoadTorture.cpp:186
     #26 std::__invoke_impl<void, UnitLoadTorture::testLoadTorture()::<lambda()> > (__f=...) at /usr/include/c++/7/bits/invoke.h:60
     #27 std::__invoke<UnitLoadTorture::testLoadTorture()::<lambda()> > (__fn=...) at /usr/include/c++/7/bits/invoke.h:95
     #28 std::thread::_Invoker<std::tuple<UnitLoadTorture::testLoadTorture()::<lambda()> > >::_M_invoke<0> (this=0x55e994cffe18) at /usr/include/c++/7/thread:234
     #29 std::thread::_Invoker<std::tuple<UnitLoadTorture::testLoadTorture()::<lambda()> > >::operator() (this=0x55e994cffe18) at /usr/include/c++/7/thread:243
     #30 std::thread::_State_impl<std::thread::_Invoker<std::tuple<UnitLoadTorture::testLoadTorture()::<lambda()> > > >::_M_run(void) (this=0x55e994cffe10) at /usr/include/c++/7/thread:186
     #31 0x00007fda22de366f in ?? () from /usr/lib/x86_64-linux-gnu/libstdc++.so.6
     #32 0x00007fda228f66db in start_thread (arg=0x7fd9fffff700) at pthread_create.c:463
     #33 0x00007fda2261f88f in clone () at ../sysdeps/unix/sysv/linux/x86_64/clone.S:95
    
    Change-Id: Ib60954e49e692082e686cb3fdc5fc9d5cfbc83c9
    Reviewed-on: https://gerrit.libreoffice.org/83047
    Reviewed-by: Michael Meeks <michael.meeks at collabora.com>
    Tested-by: Michael Meeks <michael.meeks at collabora.com>

diff --git a/common/FileUtil.cpp b/common/FileUtil.cpp
index 1c37a7afc..f94911606 100644
--- a/common/FileUtil.cpp
+++ b/common/FileUtil.cpp
@@ -56,16 +56,19 @@ namespace
 class FileDeleter
 {
     std::vector<std::string> _filesToDelete;
+    std::mutex _lock;
 public:
     FileDeleter() {}
     ~FileDeleter()
     {
-        for (auto& file: _filesToDelete)
+        std::unique_lock<std::mutex> guard(_lock);
+        for (const std::string& file: _filesToDelete)
             filesystem::remove(file);
     }
 
     void registerForDeletion(const std::string& file)
     {
+        std::unique_lock<std::mutex> guard(_lock);
         _filesToDelete.push_back(file);
     }
 };
@@ -104,11 +107,6 @@ namespace FileUtil
         return dstPath;
     }
 
-    std::string getTempFilePath(const std::string& srcDir, const std::string& srcFilename)
-    {
-        return getTempFilePath(srcDir, srcFilename, "");
-    }
-
     bool saveDataToFileSafely(const std::string& fileName, const char *data, size_t size)
     {
         const auto tempFileName = fileName + ".temp";
diff --git a/common/FileUtil.hpp b/common/FileUtil.hpp
index 0a172b98a..84b42f65c 100644
--- a/common/FileUtil.hpp
+++ b/common/FileUtil.hpp
@@ -70,14 +70,18 @@ namespace FileUtil
         removeFile(path.toString(), recursive);
     }
 
+    /// Make a temp copy of a file, and prepend it with a prefix.
+    std::string getTempFilePath(const std::string& srcDir, const std::string& srcFilename,
+                                const std::string& dstFilenamePrefix);
+
     /// Make a temp copy of a file.
     /// Primarily used by tests to avoid tainting the originals.
     /// srcDir shouldn't end with '/' and srcFilename shouldn't contain '/'.
     /// Returns the created file path.
-    std::string getTempFilePath(const std::string& srcDir, const std::string& srcFilename);
-
-    /// Make a temp copy of a file, and prepend it with a prefix.
-    std::string getTempFilePath(const std::string& srcDir, const std::string& srcFilename, const std::string& dstFilenamePrefix);
+    inline std::string getTempFilePath(const std::string& srcDir, const std::string& srcFilename)
+    {
+        return getTempFilePath(srcDir, srcFilename, std::string());
+    }
 
 } // end namespace FileUtil
 
diff --git a/test/helpers.hpp b/test/helpers.hpp
index b99177d1b..fd8e6973a 100644
--- a/test/helpers.hpp
+++ b/test/helpers.hpp
@@ -143,14 +143,19 @@ std::vector<char> readDataFromFile(std::unique_ptr<std::fstream>& file)
     return v;
 }
 
-inline
-void getDocumentPathAndURL(const std::string& docFilename, std::string& documentPath, std::string& documentURL, std::string prefix)
+inline void getDocumentPathAndURL(const std::string& docFilename, std::string& documentPath,
+                                  std::string& documentURL, std::string prefix)
 {
-    const auto testname = prefix;
+    const std::string testname = prefix;
+
+    static std::mutex lock;
+    std::unique_lock<std::mutex> guard(lock);
+
     std::replace(prefix.begin(), prefix.end(), ' ', '_');
     documentPath = FileUtil::getTempFilePath(TDOC, docFilename, prefix);
     std::string encodedUri;
-    Poco::URI::encode("file://" + Poco::Path(documentPath).makeAbsolute().toString(), ":/?", encodedUri);
+    Poco::URI::encode("file://" + Poco::Path(documentPath).makeAbsolute().toString(), ":/?",
+                      encodedUri);
     documentURL = "lool/" + encodedUri + "/ws";
     TST_LOG("Test file: " << documentPath);
 }


More information about the Libreoffice-commits mailing list