Package: libmhash2
Version: 0.9.9.9.-1

I detected memory leak in mhash library and next i found existing patch
and the patch solve the leak.

I found this (but in debian it is not applied):
https://github.com/herrwiese/gentoo-portage/blob/master/app-crypt/mhash/files/mhash-0.9.9-fix-mem-leak.patch
http://pkgs.fedoraproject.org/cgit/mhash.git/tree/mhash-0.9.9.9-fix-mem-leak.patch

Test the leak, File: mhash_memory_leak.cpp 
------------------------
//compile:  g++ -lmhash -o mhash_memory_leak mhash_memory_leak.cpp 
//check:    valgrind --leak-check=full ./mhash_memory_leak

#include <mhash.h>
#include <memory>
#include <iostream>
#include <ios>
#include <iomanip>

int main(int argc, char **argv){
  int i;
  MHASH mh;
  //create
  if((mh = mhash_init(MHASH_MD5)) == MHASH_FAILED){
    std::cout << "mhash_init() error" << std::endl;
    exit(1);
  }
  //update
  mhash(mh, "01234", 5);
  mutils_word32 size = 0;
  //get the  memory size 
  mhash_save_state_mem(mh, NULL,&size);
  if(size == 0){
    std::cout << "hash_save_state_mem(mh, NULL,&size) error" <<
std::endl;
    exit(1);
  }
  char *buf_save = new char[size];
  //save state
  if((mhash_save_state_mem(mh, buf_save,&size)) != MUTILS_OK){
    std::cout << "mhash_save_state_mem(mh, buf_save,&size) error" <<
std::endl;
    delete[] buf_save;
    exit(1);
  }
  //finish, get hash
  unsigned char *b1 = static_cast<unsigned char*>(mhash_end_m(mh, (void
* (*)(unsigned int)) malloc));
  for(i = 0; i < mhash_get_block_size(MHASH_MD5); i++){
    std::cout << std::setw(2) << std::setfill('0') << std::hex <<
static_cast<int>(b1[i]);
  }
  std::cout << std::endl;
  if(b1 != NULL){
    free(b1); b1 = NULL;
  }
  /* memory leak on the next line (in mhash_restore_state_mem()) */
  //restore state
  if((mh = mhash_restore_state_mem(buf_save)) == MHASH_FAILED){
    std::cout << " mhash_restore_state_mem(buf_save) error" <<
std::endl;
    delete[] buf_save;
    exit(1);
  }
  delete[] buf_save; buf_save = NULL;  
  //contunue to update
  mhash(mh, "56789", 5);
  unsigned char *b2 = static_cast<unsigned char*>(mhash_end_m(mh, (void
* (*)(unsigned int)) malloc));
  for(i = 0; i < mhash_get_block_size(MHASH_MD5); i++){
    std::cout << std::setw(2) << std::setfill('0') << std::hex <<
static_cast<int>(b2[i]);
  }
  std::cout << std::endl;
  if(b2 != NULL){
    free(b2); b2 = NULL;
  }
  return 0;
}
------------------------

If you use the functionality in many iteration, all memory will be eaten
very quickly. It is very annoying  if it's is used in a daemon…



2.6.32-5-amd64 #1 SMP Fri May 10 08:43:19 UTC 2013 x86_64 GNU/Linux


-- 
To UNSUBSCRIBE, email to debian-bugs-dist-requ...@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmas...@lists.debian.org

Reply via email to