Browse Source

more mem fixes

avadapal 1 year ago
parent
commit
ee65057715

+ 3 - 17
2p-preprocessing/ot_blinds.cpp

@@ -123,7 +123,6 @@ void run_test_sender(uint32_t numots, uint32_t bitlength, snd_ot_flavor stype, r
 	uint32_t nsndvals = 2;
 	CBitVector **X = (CBitVector **)malloc(sizeof(CBitVector *) * nsndvals);
 	CBitVector **Y = (CBitVector **)malloc(sizeof(CBitVector *) * nsndvals);
-	CBitVector **XoplusY = (CBitVector **)malloc(sizeof(CBitVector *) * nsndvals);
 	//The masking function with which the values that are sent in the last communication step are processed
 	XORMasking *m_fMaskFct = new XORMasking(bitlength, delta);
 
@@ -203,10 +202,6 @@ void run_test_sender(uint32_t numots, uint32_t bitlength, snd_ot_flavor stype, r
   printf("\n\nLearnt Gamma0 = (X1 /cdot Y0) /oplus T------>>>>>> \n");
   response.PrintHex();
  #endif
-	 // std::ofstream gammafile0, X0file, Y0file;
-	 // gammafile0.open ("gamma0.txt", std::ios::out);
-	 // X0file.open("X0.txt", std::ios::out);
-	 // Y0file.open("Y0.txt", std::ios::out);
 
 	  int fd = open("./y0", O_CREAT | O_WRONLY | O_TRUNC, 0600);;
  	  ssize_t bytes = write(fd, Y[0]->GetArr(), Y[0]->GetSize());
@@ -231,8 +226,10 @@ void run_test_sender(uint32_t numots, uint32_t bitlength, snd_ot_flavor stype, r
 	for (uint32_t i = 0; i < nsndvals; i++)
 	{
 		delete (X[i]);
+		delete (Y[i]);
 	}
 	free(X);
+	free(Y);
  
 	delta.delCBitVector();
 	delete m_fMaskFct;
@@ -341,18 +338,7 @@ void run_test_receiver(uint32_t numots, uint32_t bitlength, snd_ot_flavor stype,
 	   std::cout << "X1: \n\n";
 	   X1.PrintHex();
    #endif
-	//  gammafile1.open ("gamma1.txt", std::ios::out);
-	//  X1file.open("X1.txt", std::ios::out);
-	//  Y1file.open("Y1.txt", std::ios::out);
-	// for(size_t j = 0; j < numots; ++j)
-	// {
-	// //	std::cout << (int) response.GetBitNoMask(j);
-	// 	gammafile1 << (int) response.GetBitNoMask(j);
-	// 	X1file 	  << (int) X1.GetBitNoMask(j);
-	// 	Y1file 	  << (int) Y[0]->GetBitNoMask(j);
-	// }
- 
- 	//gammafile1.close();
+
 	delete m_fMaskFct;
 //	choices.delCBitVector();
 	response.delCBitVector();

+ 29 - 32
2p-preprocessing/preprocessing.cpp

@@ -65,6 +65,7 @@ leaf_t val;
 using namespace dpf;
 
 #include "mpc.h"
+
 void generate_random_targets(uint8_t **target_share_read, size_t n_threads, bool party, size_t expo)
 {
     for (size_t j = 0; j < 64; ++j)
@@ -95,7 +96,7 @@ void compute_CW(bool party, tcp::socket &sout, __m128i L, __m128i R, uint8_t bit
       int qfd = open(qfile.c_str(), O_RDWR);
       X = (__m128i *)mmap(NULL, 8 * sizeof(__m128i),
                           PROT_READ, MAP_PRIVATE, qfd, 0);
-
+      close(qfd);
       qfile = std::string("./x1");
       qfd = open(qfile.c_str(), O_RDWR);
       Y = (__m128i *)mmap(NULL, 8 * sizeof(__m128i),
@@ -111,6 +112,7 @@ void compute_CW(bool party, tcp::socket &sout, __m128i L, __m128i R, uint8_t bit
       X = (__m128i *)mmap(NULL, 8 * sizeof(__m128i),
                           PROT_READ, MAP_PRIVATE, qfd, 0);
 
+      close(qfd);
       qfile = std::string("./x0");
       qfd = open(qfile.c_str(), O_RDWR);
       Y = (__m128i *)mmap(NULL, 8 * sizeof(__m128i),
@@ -272,9 +274,9 @@ inline void evalfull_mpc(const size_t &nodes_per_leaf, const size_t &depth, cons
 
     for (size_t layer = 0; layer < depth; ++layer)
     {
-#ifdef VERBOSE
-        printf("layer = %zu\n", layer);
-#endif
+				#ifdef VERBOSE
+				 printf("layer = %zu\n", layer);
+				#endif
         curlayer = 1 - curlayer;
 
         size_t i = 0, j = 0;
@@ -287,9 +289,9 @@ inline void evalfull_mpc(const size_t &nodes_per_leaf, const size_t &depth, cons
 
         for (i = nextbit, j = nextbit; j < nodes_in_prev_layer - 1; ++j, i += 2)
         {
-            traverse(prgkey, s[1 - curlayer][j], &s[curlayer][i]);
-            L ^= s[curlayer][i];
-            R ^= s[curlayer][i + 1];
+          traverse(prgkey, s[1 - curlayer][j], &s[curlayer][i]);
+          L ^= s[curlayer][i];
+          R ^= s[curlayer][i + 1];
         }
 
         if (nodes_in_prev_layer > j)
@@ -367,36 +369,34 @@ void convert_shares(__m128i **output, int8_t **flags, size_t n_threads, size_t d
             }
         }
 
-#ifdef DEBUG
-        int8_t out = flags[0][j];
-        int8_t out_rec;
+				#ifdef DEBUG
+				        int8_t out = flags[0][j];
+				        int8_t out_rec;
 
-        boost::asio::write(sb, boost::asio::buffer(&out, sizeof(out)));
-        boost::asio::read(sb, boost::asio::buffer(&out_rec, sizeof(out_rec)));
-        out_rec = out_rec + out;
+				        boost::asio::write(sb, boost::asio::buffer(&out, sizeof(out)));
+				        boost::asio::read(sb, boost::asio::buffer(&out_rec, sizeof(out_rec)));
+				        out_rec = out_rec + out;
 
 
-        if (out_rec != 0)
-            std::cout << j << "(flags) --> " << (int)out_rec << std::endl
-                      << std::endl;
+				        if (out_rec != 0)
+				            std::cout << j << "(flags) --> " << (int)out_rec << std::endl
+				                      << std::endl;
 
-        __m128i out2 = output[0][j];
-        __m128i out_rec2;
+				        __m128i out2 = output[0][j];
+				        __m128i out_rec2;
 
-        boost::asio::write(sb, boost::asio::buffer(&out2, sizeof(out2)));
-        boost::asio::read(sb, boost::asio::buffer(&out_rec2, sizeof(out_rec2)));
-        out_rec2 = out_rec2 + out2;
-        if (out_rec2[0] != 0)
-            std::cout << j << "--> " << out_rec2[0] << std::endl;
-#endif
+				        boost::asio::write(sb, boost::asio::buffer(&out2, sizeof(out2)));
+				        boost::asio::read(sb, boost::asio::buffer(&out_rec2, sizeof(out_rec2)));
+				        out_rec2 = out_rec2 + out2;
+				        if (out_rec2[0] != 0)
+				            std::cout << j << "--> " << out_rec2[0] << std::endl;
+				#endif
     }
 
     for (size_t i = 0; i < n_threads; ++i)
     {
-
         int64_t pm = 0;
         int64_t rb;
-
         arc4random_buf(&rb, sizeof(rb));
         for (size_t j = 0; j < db_nitems; ++j)
         {
@@ -526,12 +526,9 @@ int main(int argc, char *argv[])
     auto start = std::chrono::steady_clock::now();
 
 
-#ifdef VERBOSE
-    printf("n_threads = %zu\n\n", n_threads);
-#endif
-
-
-
+		#ifdef VERBOSE
+		    printf("n_threads = %zu\n\n", n_threads);
+		#endif
 
 		uint8_t **target_share_read = new uint8_t *[thread_per_batch];
     for (size_t i = 0; i < n_threads; i++) target_share_read[i] = new uint8_t[64];

+ 2 - 1
duoram-online/duoram-utils.h

@@ -125,7 +125,7 @@ int read_database_shares(bool party, size_t db_nitems)
           close(in);
           return 1;
         }
-
+        close(in);
     }
     if(!party)
     {
@@ -137,6 +137,7 @@ int read_database_shares(bool party, size_t db_nitems)
           close(in);
             return 1;
       }
+      close(in);
     }
 	return 0;
 }

+ 2 - 0
duoram-online/duoram.cpp

@@ -386,6 +386,7 @@ int main(const int argc, const char * argv[])
     delete[] Gamma_reads;
     delete[] WritePb_ind_reads_recv;
     delete[] WritePb_ind_reads;
+    delete[] read_out_independent_reads;
     auto end_ind_reads = std::chrono::steady_clock::now();
     std::chrono::duration<double> elapsed_seconds_ind_reads = end_ind_reads - start_ind_reads;
     //printf("elapsed_seconds_ind_reads = %f\n",elapsed_seconds_ind_reads.count());
@@ -410,6 +411,7 @@ int main(const int argc, const char * argv[])
        std::cout << print_reconstruction(sockets_[0], read_out_dependent_reads[r]) << std::endl;
       #endif
     }
+    delete[] read_out_dependent_reads;
     delete[] where_to_read_dependent;
     auto end_dep_reads = std::chrono::steady_clock::now();
     std::chrono::duration<double> elapsed_seconds_dep_reads = end_dep_reads - start_dep_reads;

+ 29 - 0
duoram-online/p2.cpp

@@ -229,8 +229,14 @@ int main(int argc, char* argv[])
        Gamma1_reads[r] = Gamma1;
      }
 
+     delete[] reads_shift_from_P0;
+     delete[] reads_shift_from_P1;
+     delete[] rotate;
+
      boost::asio::write(sockets_0[4], boost::asio::buffer(Gamma0_reads, number_of_ind_reads * sizeof(DB_t)));  
      boost::asio::write(sockets_1[4], boost::asio::buffer(Gamma1_reads, number_of_ind_reads * sizeof(DB_t)));
+     delete[] Gamma0_reads;
+     delete[] Gamma1_reads;
      communication_cost_ind_read += number_of_ind_reads * sizeof(DB_t);
      communication_cost_ind_read += number_of_ind_reads * sizeof(DB_t);
     auto end_ind_reads = std::chrono::steady_clock::now();
@@ -252,11 +258,34 @@ int main(int argc, char* argv[])
        communication_cost_dep_read += sizeof(Gamma0);
        communication_cost_dep_read += sizeof(Gamma1);
      }
+
+
+
     auto end_dep_reads = std::chrono::steady_clock::now();
     std::chrono::duration<double> elapsed_seconds_dep_reads = end_dep_reads - start_dep_reads;
     dependent_read_time = elapsed_seconds_dep_reads.count();
   }
 
+delete[] WriteP0_recv;
+delete[] WriteP1_recv;
+
+delete[] Gamma0_;
+delete[] Gamma1_;
+delete[] update_message0;
+delete[] update_message1;
+delete[] FCW;
+free(X0);
+free(X1);
+free(b);
+free(c);
+free(d);
+free(reading_b);
+free(reading_c);
+free(reading_d);
+free(writing_b);
+free(writing_c);
+free(writing_d);
+
 std::cout << "write_time = " << write_time << std::endl;
 std::cout << "communication_cost_writes = " << communication_cost_write << " bytes" << std::endl; 
 

+ 1 - 0
preprocessing/preprocessing.cpp

@@ -221,6 +221,7 @@ int main(int argc, char * argv[])
     free(leafbits);
     free(output);
     free(flags);
+    free(final_correction_word);
     delete[] target_share_read;
     /* For the artifact, don't actually write these in order to not use very
      * large amounts of storage

+ 2 - 15
preprocessing/share-conversion.h

@@ -108,12 +108,9 @@ void P2_xor_to_additive(tcp::socket& s0, tcp::socket& s1, size_t socket_no)
 void xor_to_additive(bool party, uint8_t * target_share_read, tcp::socket& sb, tcp::socket& s2, const size_t height, int64_t& R_share)
 {
     const size_t logn = height;
-    //std::array<uint64_t, logn> b, b_blinded, b_recv;
 
     int64_t b[64], b_blinded[64], b_recv[64]; 
     
- 
-
     for(size_t j = 0; j < logn; ++j)
     {
       b[j] = target_share_read[logn-j - 1];
@@ -130,10 +127,7 @@ void xor_to_additive(bool party, uint8_t * target_share_read, tcp::socket& sb, t
      uint64_t b_ = binary_to_decimal(b, logn);;
      std::cout << "b_ = " << b_ << std::endl;
     #endif
-    
-    // std::array<uint64_t, logn> c_mul;
-    // std::array<uint64_t, logn> d;
-    //uint64_t c_mul[logn], d[logn];
+
     int64_t * c_mul = (int64_t*) malloc(logn * sizeof(int64_t));
     int64_t * d     = (int64_t*) malloc(logn * sizeof(int64_t));
     int64_t BLIND, Gamma;
@@ -153,8 +147,6 @@ void xor_to_additive(bool party, uint8_t * target_share_read, tcp::socket& sb, t
     std::cout << "BLIND = " << BLIND << std::endl;
     std::cout << "Gamma = " << Gamma << std::endl;
     #endif
-    
-   // uint64_t R_share = 0;
  
     if(!party) 
     {
@@ -188,14 +180,10 @@ void xor_to_additive(bool party, uint8_t * target_share_read, tcp::socket& sb, t
        std::cout << "mul_Rec = " << mul_Rec << std::endl;
      }
 
-     //std::array<uint64_t, logn> b_reconstruction_;
-     //std::array<uint64_t, logn> d_reconstruction_;
-    // uint64_t b_reconstruction_[logn], d_reconstruction_[logn], d_recv[logn];
      int64_t * b_reconstruction_         = (int64_t*) malloc(logn * sizeof(int64_t));
      int64_t * d_reconstruction_ = (int64_t*) malloc(logn * sizeof(int64_t));
      int64_t * d_recv    = (int64_t*) malloc(logn * sizeof(int64_t));
      
-     //std::array<uint64_t, logn> d_recv;
      for(size_t j = 0; j < logn; ++j)
      {
       boost::asio::write(sb, boost::asio::buffer(&d[j], sizeof(d[j])));
@@ -238,8 +226,6 @@ void xor_to_additive(bool party, uint8_t * target_share_read, tcp::socket& sb, t
 
      std::free(c_mul);
      std::free(d);
-      
-  // return R_share;
 }
 
 
@@ -353,5 +339,6 @@ void convert_shares(size_t i, __m128i ** output, int8_t ** flags, size_t n_threa
     }
 		#endif
 	}
+  free(flags_);
 	 // write_evalfull_outs_into_a_file(party, i, db_nitems, flags[i],  leaves[i], final_correction_word[i]); 
 }