Browse Source

solved more leaks and issues associated

Carlos Aguilar 6 years ago
parent
commit
9896cc7a71

+ 2 - 2
apps/server/PIRSession.cpp

@@ -406,10 +406,8 @@ void PIRSession::downloadWorker()
     {
       // Compute and allocate the size in bytes of a query ELEMENT of dimension j 
       msg_size = cryptoMethod->getPublicParameters().getQuerySizeFromRecLvl(j+1) / 8;
-      char buf[msg_size];
       boost::asio::socket_base::receive_buffer_size opt(65535);
       sessionSocket.set_option(opt);
-      auto boost_buffer = boost::asio::buffer(buf,msg_size); 
   //    boost_buffer = new boost::asio::buffer(buf, msg_size); 
 #ifdef DEBUG
       cout << "PIRSession: Size of the query element to be received is " << msg_size << endl;
@@ -419,6 +417,8 @@ void PIRSession::downloadWorker()
       // Iterate over all the elements of the query corresponding to the j-th dimension
       for (unsigned int i = 0; i < pirParam.n[j]; i++)
       {
+      char *buf = (char *) malloc(msg_size*sizeof(char));
+      auto boost_buffer = boost::asio::buffer(buf,msg_size); 
       if (i==0 && j == 0) cout << "PIRSession: Waiting for query elements ..." << endl;
         // Get a query element 
          //( async_read(sessionSocket, boost_buffer,boost::bind(&blo,boost::asio::placeholders::error)) );

+ 2 - 0
apps/simplepir/simplePIR.cpp

@@ -173,6 +173,8 @@ bool run(DBHandler *db, uint64_t chosen_element, PIRParameters params){
   delete imported_db;
   r_generator->freeQueries();
   delete r_generator;
+  delete r_extractor;
+  delete crypto;
   free(result);
   free(db_element);
   

+ 2 - 3
crypto/NFLLWE.cpp

@@ -275,7 +275,6 @@ void  NFLLWE::enc(lwe_cipher *c, poly64 m)
 	NFLLWE_DEBUG_MESSAGE("Encrypting m: ",m, 4);
 
 	c->a = (poly64) calloc(polyDegree * 2 * nbModuli,  sizeof(uint64_t));
-  std::cout << "!!!!!!!!!!!!!!!!!!!!!!! " << c->a << std::endl;
 	c->b = c->a + polyDegree * nbModuli;
 
 	// tmpa and tmpb are used to access the nbModuli polynoms of the CRT
@@ -451,8 +450,8 @@ void NFLLWE::dec(poly64 m, lwe_cipher *c)
 	  }
     
     delete[] tmprez;
-    mpz_clear(moduliProduct);
-    mpz_clear(tmpz);
+    mpz_clears(moduliProduct, tmpz, magicConstz, bitmaskz, NULL);
+
   } else { // nbModuli=1
 	
 	

+ 4 - 1
pir/replyGenerator/GenericPIRReplyGenerator.cpp

@@ -23,7 +23,10 @@ GenericPIRReplyGenerator::GenericPIRReplyGenerator():
   repliesAmount(0),
   repliesIndex(0)
 {
-   mutex.lock();
+  pirParam.d = 0;
+  pirParam.alpha = 0;
+  for (int i = 0 ; i < MAX_REC_LVL; i++) pirParam.n[i] = 0;
+  mutex.lock();
 }
 
 GenericPIRReplyGenerator::GenericPIRReplyGenerator(PIRParameters& param, DBHandler *db):

+ 1 - 1
pir/replyGenerator/GenericPIRReplyGenerator.hpp

@@ -45,7 +45,7 @@ class GenericPIRReplyGenerator
   protected:
 
 
-    PIRParameters emptyPIRParams;
+  PIRParameters emptyPIRParams;
 	PIRParameters& pirParam;
 	unsigned int maxChunkSize;
 	DBHandler* dbhandler;	

+ 9 - 6
pir/replyGenerator/PIRReplyGeneratorNFL_internal.cpp

@@ -27,7 +27,13 @@
 //#define SNIFFER //Use this to activate a sniffer like behavior
 
 PIRReplyGeneratorNFL_internal::PIRReplyGeneratorNFL_internal():
-  lwe(false)
+  lwe(false),
+  currentMaxNbPolys(0),
+  queriesBuf(NULL),
+  current_query_index(0),
+  current_dim_index(0),
+  input_data(NULL),
+  cryptoMethod(NULL)
 {
 }
 
@@ -729,15 +735,14 @@ void PIRReplyGeneratorNFL_internal::initQueriesBuffer() {
 
 void PIRReplyGeneratorNFL_internal::pushFakeQuery()
 {
-  char* query_element = cryptoMethod->encrypt(0, 1); 
+  char* query_element;
 
   for (unsigned int dim  = 0 ; dim < pirParam.d ; dim++) {
     for(unsigned int j = 0 ; j < pirParam.n[dim] ; j++) {
+      query_element = cryptoMethod->encrypt(0, 1); 
       pushQuery(query_element, cryptoMethod->getPublicParameters().getCiphertextBitsize()/8, dim, j); 
     }
   }
-
-  free(query_element);
 }
 
 
@@ -875,8 +880,6 @@ void PIRReplyGeneratorNFL_internal::freeQueries()
     {
 		  if (queriesBuf != NULL && queriesBuf[i] != NULL && queriesBuf[i][0][j].a != NULL)
       {
-  std::cout << "????????????????????????? " << queriesBuf[i][0][j].a << std::endl;
-        
         free(queriesBuf[i][0][j].a); //only free a because a and b and contingus, see pushQuery
         queriesBuf[i][0][j].a = NULL;
       }