LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 05-09-2006, 04:09 AM   #1
wangjinyi
Member
 
Registered: Sep 2004
Posts: 60

Rep: Reputation: 15
memory leak in stl_hashtable


Code:
#ifndef	__RDHASHTABLE_H__
#define	__RDHASHTABLE_H__

#include "ext/stl_hashtable.h"
#include "iostream"

#pragma GCC system_header

using namespace	std;
using namespace	__gnu_cxx;

//set for storeLogic
struct dataCStruct {
	time_t timestamp;
	unsigned char srcip[4];
	unsigned char dstip[4];
	int bytes;
};

struct dataCAndKeyStruct {
	dataCStruct* dataC;
	char* key;
};

struct GetKey {char* operator()(dataCAndKeyStruct dataCKey) const {return dataCKey.key;}};

struct EqualKey	{bool operator()(char* key1, char* key2) const {return strcmp(key1, key2) == 0;}};

extern GetKey getKey;
extern EqualKey equalKey;
extern hash<char*> rdHashFunc;

typedef	hashtable<dataCAndKeyStruct, char*, hash<char*>, GetKey, EqualKey> rdHashtable;
typedef _Hashtable_iterator<dataCAndKeyStruct, char*,  hash<char*>, GetKey, EqualKey, std::__alloc> rdIt;

#define RDHASHBUCKETCOUNT 1000

#define RDHASHTABLE() rdHashtable(RDHASHBUCKETCOUNT,rdHashFunc,equalKey,getKey);

#endif
that is the main code. later, i new a rdHashtable, and
malloc many dataCAndKeyStruct with dataCStruct and key , and insert those dataCAndKeyStruct into rdHashtable. all is ok, but when delete rdHashtable, the memory of key can't be free.
oh, god.

i do the free of dataCStruct myself, but when i free the key, there is a core dump.

i am on fedora core 2.

why?
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Memory Leak?! RoaCh Of DisCor Linux - General 9 05-07-2005 12:26 AM
Memory leak?! nyk Programming 10 01-24-2005 07:08 PM
Possible Memory Leak liquidcool Linux - General 3 10-07-2004 08:38 AM
memory leak mdk Mandriva 1 09-17-2004 10:54 AM
Memory Leak when using memory debugging C program on SuSE SLES8 babalina Linux - Distributions 0 10-06-2003 09:39 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 11:54 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration