Bonjour,

j'ai des soucis avec valgrind et la classe String car cela provoque des fuites mémoire et je ne comprends pas pourquoi.
Le problème se pose avec ma données membre string date_lim_conso.
Ci-joint le rapport de valgrind le .cpp de ma classe et mon main.

Merci d'avance =)



voici ma classe, c'est une classe dérivée de Produit :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
 
Sandwich::Sandwich(float hauteur_prod,float prix_prod,const string & chaine): Produit(hauteur_prod,prix_prod) {
	cout << "Construction d'un objet de type Sandwich \n";	
	date_lim_conso=chaine;
}
 
Sandwich::~Sandwich(){
	cout << "destruction d'un objet de type Sandwich \n";	
}
 
string Sandwich::ObtenirDateLimConso()const{
	return date_lim_conso;
}
 
void Sandwich::AfficherDatelim()const{
	cout << "date limite de consommation : " << date_lim_conso << "\n" ;
}
 
void Sandwich::AfficherProd()const{
	Produit::AfficherProd();
	this->AfficherDatelim();
}
 
char Sandwich::ObtenirType()const{
	return 'S';
}
des bouts de mon main :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
 
int main(void){
	// Initialisation d'un tableau dynamique
	int taille=4;
	Produit** tab;
	tab=new Produit*[taille];
        tab[1]=new Sandwich(4.0,5.0,"1993 12 09");
	cout << "\n<SANDWICH> \n \n" ;
	tab[1]->AfficherProd();
 
	for(unsigned int i=0; i<taille; i++)
	{
		//boucle pour eliminer les tab[i]
		if(tab[i]!=NULL)
		{delete tab[i];
		tab[i]=NULL;}
	}
 
	//boucle pour eliminer tab
	if(tab!=NULL)
	{delete [] tab;
	tab=NULL;}
Mon souci, avec valgrind sont les fuites memoires et les ERRORS qui proviennent de cette ligne qui s’éliminent dès que je mets en commentaire cette ligne :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
 
date_lim_conso=chaine;
voici le rapport de valgrind :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
==2627== HEAP SUMMARY:
==2627==     in use at exit: 46 bytes in 2 blocks
==2627==   total heap usage: 9 allocs, 7 frees, 670 bytes allocated
==2627== 
==2627== 46 bytes in 2 blocks are definitely lost in loss record 1 of 1
==2627==    at 0x402B9B4: operator new(unsigned int) (in /usr/lib/valgrind/vgpreload_memcheck-x86-linux.so)
==2627==    by 0x40D57D3: std::string::_Rep::_S_create(unsigned int, unsigned int, std::allocator<char> const&) (in /usr/lib/i386-linux-gnu/libstdc++.so.6.0.16)
==2627==    by 0x40D7A47: char* std::string::_S_construct<char const*>(char const*, char const*, std::allocator<char> const&, std::forward_iterator_tag) (in /usr/lib/i386-linux-gnu/libstdc++.so.6.0.16)
==2627==    by 0x40D7BB5: std::basic_string<char, std::char_traits<char>, std::allocator<char> >::basic_string(char const*, std::allocator<char> const&) (in /usr/lib/i386-linux-gnu/libstdc++.so.6.0.16)
==2627==    by 0x41614D2: (below main) (libc-start.c:226)
==2627== 
==2627== LEAK SUMMARY:
==2627==    definitely lost: 46 bytes in 2 blocks
==2627==    indirectly lost: 0 bytes in 0 blocks
==2627==      possibly lost: 0 bytes in 0 blocks
==2627==    still reachable: 0 bytes in 0 blocks
==2627==         suppressed: 0 bytes in 0 blocks
==2627== 
==2627== For counts of detected and suppressed errors, rerun with: -v
==2627== ERROR SUMMARY: 1 errors from 1 contexts (suppressed: 0 from 0)