]> git.lizzy.rs Git - minetest.git/blobdiff - src/serialization.cpp
Fix race condition in registration leading to duplicate create_auth calls
[minetest.git] / src / serialization.cpp
index d4d7b5f6efa9c9105fdfa73fa9986da61b830adc..11164a0ede10952f78b174a008f8df7996dfceaa 100644 (file)
@@ -108,7 +108,6 @@ void decompressZlib(std::istream &is, std::ostream &os, size_t limit)
        char output_buffer[bufsize];
        int status = 0;
        int ret;
-       int bytes_read = 0;
        int bytes_written = 0;
        int input_buffer_len = 0;
 
@@ -122,8 +121,6 @@ void decompressZlib(std::istream &is, std::ostream &os, size_t limit)
 
        z.avail_in = 0;
 
-       //dstream<<"initial fail="<<is.fail()<<" bad="<<is.bad()<<std::endl;
-
        for(;;)
        {
                int output_size = bufsize;
@@ -147,19 +144,13 @@ void decompressZlib(std::istream &is, std::ostream &os, size_t limit)
                        is.read(input_buffer, bufsize);
                        input_buffer_len = is.gcount();
                        z.avail_in = input_buffer_len;
-                       //dstream<<"read fail="<<is.fail()<<" bad="<<is.bad()<<std::endl;
                }
                if(z.avail_in == 0)
                {
-                       //dstream<<"z.avail_in == 0"<<std::endl;
                        break;
                }
 
-               //dstream<<"1 z.avail_in="<<z.avail_in<<std::endl;
                status = inflate(&z, Z_NO_FLUSH);
-               //dstream<<"2 z.avail_in="<<z.avail_in<<std::endl;
-               bytes_read += is.gcount() - z.avail_in;
-               //dstream<<"bytes_read="<<bytes_read<<std::endl;
 
                if(status == Z_NEED_DICT || status == Z_DATA_ERROR
                                || status == Z_MEM_ERROR)
@@ -168,16 +159,11 @@ void decompressZlib(std::istream &is, std::ostream &os, size_t limit)
                        throw SerializationError("decompressZlib: inflate failed");
                }
                int count = output_size - z.avail_out;
-               //dstream<<"count="<<count<<std::endl;
                if(count)
                        os.write(output_buffer, count);
                bytes_written += count;
                if(status == Z_STREAM_END)
                {
-                       //dstream<<"Z_STREAM_END"<<std::endl;
-
-                       //dstream<<"z.avail_in="<<z.avail_in<<std::endl;
-                       //dstream<<"fail="<<is.fail()<<" bad="<<is.bad()<<std::endl;
                        // Unget all the data that inflate didn't take
                        is.clear(); // Just in case EOF is set
                        for(u32 i=0; i < z.avail_in; i++)
@@ -208,30 +194,11 @@ struct ZSTD_Deleter {
        }
 };
 
-#if defined(__MINGW32__) && !defined(__MINGW64__)
-/*
- * This is exactly as dumb as it looks.
- * Yes, this is a memory leak. No, we don't have better solution right now.
- */
-template<typename T> class leaky_ptr
-{
-       T *value;
-public:
-       leaky_ptr(T *value) : value(value) {};
-       T *get() { return value; }
-};
-#endif
-
 void compressZstd(const u8 *data, size_t data_size, std::ostream &os, int level)
 {
-#if defined(__MINGW32__) && !defined(__MINGW64__)
-       // leaks one context per thread but doesn't crash :shrug:
-       thread_local leaky_ptr<ZSTD_CStream> stream(ZSTD_createCStream());
-#else
        // reusing the context is recommended for performance
-       // it will destroyed when the thread ends
+       // it will be destroyed when the thread ends
        thread_local std::unique_ptr<ZSTD_CStream, ZSTD_Deleter> stream(ZSTD_createCStream());
-#endif
 
 
        ZSTD_initCStream(stream.get(), level);
@@ -276,14 +243,9 @@ void compressZstd(const std::string &data, std::ostream &os, int level)
 
 void decompressZstd(std::istream &is, std::ostream &os)
 {
-#if defined(__MINGW32__) && !defined(__MINGW64__)
-       // leaks one context per thread but doesn't crash :shrug:
-       thread_local leaky_ptr<ZSTD_DStream> stream(ZSTD_createDStream());
-#else
        // reusing the context is recommended for performance
-       // it will destroyed when the thread ends
+       // it will be destroyed when the thread ends
        thread_local std::unique_ptr<ZSTD_DStream, ZSTD_Deleter> stream(ZSTD_createDStream());
-#endif
 
        ZSTD_initDStream(stream.get());