IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

MFC Discussion :

[VC++6] probleme fuite memoire CLIST ?


Sujet :

MFC

  1. #1
    Nouveau membre du Club
    Profil pro
    Inscrit en
    Novembre 2005
    Messages
    39
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Novembre 2005
    Messages : 39
    Points : 31
    Points
    31
    Par défaut [VC++6] probleme fuite memoire CLIST ?
    bonjour,

    j'utilise une extension de la class CLIST, CLISTEX.

    voici la class CLIST utiliser :
    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
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    class CListSMS : public CListEx <CTeleSSMS,CTeleSSMS>, CDefaultGestionnaire
    {
    public:
    	CListSMS();
     
    	~CListSMS();
     
     
    	void GetAction();
    	int GetStatus();
     
     
    	inline int ValeurTimer(){return GetValeurTimer();};
    	inline CLog& Log(){return *m_log;};
     
    	//=============================================
    	//
    	//=============================================
    	inline CTeleSSMS* search(const int& i)
    	{
    		POSITION pos;
    		CTeleSSMS *elt;
    		elt= new CTeleSSMS();
     
    		for(pos=GetHeadPosition();pos!=NULL;)
    		{
    			*elt = GetNext(pos);
    			if(elt->id == i)
    			{
    				return elt;
    			}
    		}
    		return NULL;
    		//return;
    	};
     
    	//=============================================
    	//
    	//=============================================
    	POSITION searchPos(const int& i)
    	{
    		POSITION pos;
    		CTeleSSMS elt;
     
    		for(pos=GetHeadPosition();pos!=NULL;)
    		{
    			elt=GetNext(pos);
    			if(elt.id == i)
    			{
    				return (pos!=NULL?pos:GetTailPosition());
    			}
    		}
    		return pos;
    	};
     
    };

    et voici le traitement:
    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
    			for(pos=m_listsms.GetHeadPosition();pos!=NULL;)
    			{
    				elt = m_listsms.GetAt(pos);
     
    				//OPERATION ...
     
     
    				if(pos!=NULL) //on sait jamais
    				{
    					//ici perte de 4ko a chaque passage !!!
    					m_listsms.SetAt(pos,elt);
    				}
    				elt = m_listsms.GetNext(pos);
     
    			}
    donc le probleme c'est qu'a l'interrieur de la class CTeleSSMS y a des pointeur je passe donc par un operateur de recopie.
    mais je ne comprend pas ou je perd cette memoire.

    je pense que cette erreur me fait perdre apres la gestion des timers. Je m'explique j'ai deux timers, 1 a la seconde et l'autre a 5 seconde. au bout d'un moment le timer a 1 seconde s'arrete apres avoir repositionner le timer (traitement a l'interrieur du timer, KillTimer, ACtion, Setimer), je refait bien le settimer mais plus rien apres je reviens pas dans le timer.
    mais le deuxieme timer continue bien.

    la perte de 4ko ce situe dans le timer 5s.

    personnellement je suis perdu, je pense que vous ne me comprendrais pas non plus, mais j'essaie quand meme.


    aidez moiiiiiiii

    merci par avance
    Hervé

  2. #2
    Rédacteur
    Avatar de farscape
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Novembre 2003
    Messages
    9 055
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Alpes Maritimes (Provence Alpes Côte d'Azur)

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Novembre 2003
    Messages : 9 055
    Points : 17 323
    Points
    17 323
    Par défaut
    salut,
    bon apparemment tu n'utilises pas une reference pour le deuxieme argument de ta CList.
    a tu definit l'operateur d'affectation et le constructeur de copie pour ta classe
    CTeleSSMS ?

  3. #3
    Nouveau membre du Club
    Profil pro
    Inscrit en
    Novembre 2005
    Messages
    39
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Novembre 2005
    Messages : 39
    Points : 31
    Points
    31
    Par défaut
    oui, d'ailleurs c'est le meme code pour l'un et pour l'autre

    tu veux voir le code ?

  4. #4
    Rédacteur
    Avatar de farscape
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Novembre 2003
    Messages
    9 055
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Alpes Maritimes (Provence Alpes Côte d'Azur)

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Novembre 2003
    Messages : 9 055
    Points : 17 323
    Points
    17 323
    Par défaut
    Citation Envoyé par athilla
    oui, d'ailleurs c'est le meme code pour l'un et pour l'autre

    tu veux voir le code ?
    oui pour ces deux fonctions.
    tu fais des allocations memoires dans cette classe ?
    si c'est le cas tu liberes la memoire avant reaffectation ?

  5. #5
    Nouveau membre du Club
    Profil pro
    Inscrit en
    Novembre 2005
    Messages
    39
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Novembre 2005
    Messages : 39
    Points : 31
    Points
    31
    Par défaut
    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
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    /*******************************************************************************
    CTeleSSMS
    --------------------------------------------------------------------------------
     
      constructeur de recopie
     
    ********************************************************************************/
     
    CTeleSSMS::CTeleSSMS(const CTeleSSMS & t)
    {
    	int i;
    	this->id = t.id;
    	this->liste = t.liste;
    	this->onInit = t.onInit;
    	this->m_modem_init_ok = t.m_modem_init_ok;
    	this->g_DCB = t.g_DCB;
    	this->m_iEtatCom = t.m_iEtatCom;
    	this->g_hcom = t.g_hcom;
    	this->m_transition = t.m_transition;
    	this->m_recopie = t.m_recopie;
     
     
    	for(i=0; i<MAX_ACTION_MEDIA; i++)
    	{
    		this->m_lastaction[i].m_idcc = t.m_lastaction[i].m_idcc;
    		this->m_lastaction[i].m_idaction = t.m_lastaction[i].m_idaction;
    		this->m_lastaction[i].m_code = t.m_lastaction[i].m_code;
    		this->m_lastaction[i].m_idactionmedia = t.m_lastaction[i].m_idactionmedia;
    		this->m_lastaction[i].m_idmedia = t.m_lastaction[i].m_idmedia;
    		this->m_lastaction[i].m_idtypeaction = t.m_lastaction[i].m_idtypeaction;
    		this->m_lastaction[i].demande = t.m_lastaction[i].demande;
    		this->m_lastaction[i].niveau = t.m_lastaction[i].niveau;
    		this->m_lastaction[i].m_now = t.m_lastaction[i].m_now;
    		this->m_lastaction[i].m_acquit = t.m_lastaction[i].m_acquit;
    		this->m_lastaction[i].m_action = t.m_lastaction[i].m_action;
    		strcpy(this->m_lastaction[i].telephone,t.m_lastaction[i].telephone);
    	}
     
    	if(this->m_transition==true)
    		this->m_default = new CDefaultGestionnaire("TELESSMS");
    	else
    		this->m_default = new CDefaultGestionnaire("TELESSMS",1);
     
     
    	strcpy(this->m_default->m_filename, t.m_default->m_filename);
    	strcpy(this->m_default->m_db_user, t.m_default->m_db_user);
    	strcpy(this->m_default->m_db_passwd, t.m_default->m_db_passwd);
    	strcpy(this->m_default->m_db_name, t.m_default->m_db_name);
    	strcpy(this->m_default->m_db_host, t.m_default->m_db_host);
    	strcpy(this->m_default->m_log_filename, t.m_default->m_log_filename);	
     
    /*** normalement lut dans le fichier ini au moment du new CDefaultGestionnaire ***/
    	this->m_default->m_val_timer = t.m_default->m_val_timer;
    	this->m_default->m_type_media = t.m_default->m_type_media;
    /*********************************************************************************/
     
     
    	delete t.m_default;
     
     
    	for(i=0; i<4; i++)
    	{
    		strcpy(this->ts_numero_telephone[i],t.ts_numero_telephone[i]);
    	}
     
    	this->ts_tempo_rappel = t.ts_tempo_rappel;
     
    }
     
     
    CTeleSSMS::operator= (CTeleSSMS & t)
    {
     
    	int i;
    	this->id = t.id;
    	this->liste = t.liste;
    	this->onInit = t.onInit;
    	this->m_modem_init_ok = t.m_modem_init_ok;
    	this->g_DCB = t.g_DCB;
    	this->m_iEtatCom = t.m_iEtatCom;
    	this->g_hcom = t.g_hcom;
    	this->m_transition = t.m_transition;
    	this->m_recopie = t.m_recopie;
     
     
    	for(i=0; i<MAX_ACTION_MEDIA; i++)
    	{
    		this->m_lastaction[i].m_idcc = t.m_lastaction[i].m_idcc;
    		this->m_lastaction[i].m_idaction = t.m_lastaction[i].m_idaction;
    		this->m_lastaction[i].m_code = t.m_lastaction[i].m_code;
    		this->m_lastaction[i].m_idactionmedia = t.m_lastaction[i].m_idactionmedia;
    		this->m_lastaction[i].m_idmedia = t.m_lastaction[i].m_idmedia;
    		this->m_lastaction[i].m_idtypeaction = t.m_lastaction[i].m_idtypeaction;
    		this->m_lastaction[i].demande = t.m_lastaction[i].demande;
    		this->m_lastaction[i].niveau = t.m_lastaction[i].niveau;
    		this->m_lastaction[i].m_now = t.m_lastaction[i].m_now;
    		this->m_lastaction[i].m_acquit = t.m_lastaction[i].m_acquit;
    		this->m_lastaction[i].m_action = t.m_lastaction[i].m_action;
    		strcpy(this->m_lastaction[i].telephone,t.m_lastaction[i].telephone);
    	}
     
    	//normalement on part dans l'operateur =  de la class CdefaultGestionnaire
    	if(this->m_transition==true)									
    		this->m_default = new CDefaultGestionnaire("TELESSMS");		
    	else															
    		this->m_default = new CDefaultGestionnaire("TELESSMS",1);	
     
    	strcpy(this->m_default->m_filename, t.m_default->m_filename);
    	strcpy(this->m_default->m_db_user, t.m_default->m_db_user);
    	strcpy(this->m_default->m_db_passwd, t.m_default->m_db_passwd);
    	strcpy(this->m_default->m_db_name, t.m_default->m_db_name);
    	strcpy(this->m_default->m_db_host, t.m_default->m_db_host);
    	strcpy(this->m_default->m_log_filename, t.m_default->m_log_filename);	
     
    /*** normalement lut dans le fichier ini au moment du new CDefaultGestionnaire ***/
    	this->m_default->m_val_timer = t.m_default->m_val_timer;
    	this->m_default->m_type_media = t.m_default->m_type_media;
    /*********************************************************************************/
     
    	for(i=0; i<4; i++)
    	{
    		strcpy(this->ts_numero_telephone[i],t.ts_numero_telephone[i]);
    	}
     
    	this->ts_tempo_rappel = t.ts_tempo_rappel;
     
    };
    je suis pas sur de savoir ou liberer la memoire.

  6. #6
    Rédacteur
    Avatar de farscape
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Novembre 2003
    Messages
    9 055
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Alpes Maritimes (Provence Alpes Côte d'Azur)

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Novembre 2003
    Messages : 9 055
    Points : 17 323
    Points
    17 323
    Par défaut
    ben deja c'est sur la destination qu'il faut liberer la memoire pas sur l'objet source.
    il faut faire un delete this->m_default avant l'allocation en fonction de l'objet source t .
    enlever delete t.m_default; tu detruis la zone memoire de l'objet source qui n'a rien demandé ...
    pareil dans l'operateur d'affectation il faut liberer avant d'allouer.
    et enfin s'assurer que dans le(s) constructeur(s) le pointeur sur objet m_default est initialisé a null.


  7. #7
    Nouveau membre du Club
    Profil pro
    Inscrit en
    Novembre 2005
    Messages
    39
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Novembre 2005
    Messages : 39
    Points : 31
    Points
    31
    Par défaut
    alors c'est la ou y a un truc qui m'echappe, liberer avant d'alloue, c'est pas sensé etre alouer pourtant!

    y a un truc qui m'echappe la.

  8. #8
    Rédacteur
    Avatar de farscape
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Novembre 2003
    Messages
    9 055
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Alpes Maritimes (Provence Alpes Côte d'Azur)

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Novembre 2003
    Messages : 9 055
    Points : 17 323
    Points
    17 323
    Par défaut
    re,
    Il ne faut pas sous estimer l’utilisation d’un objet.

    Pour un objet avec allocations mémoire on devra faire :
    1) pointeur d’allocation mis a nul dans le(s) constructeur(s).
    2) delete des différents pointeurs d’allocations systématique (si le pointeur est null pas de problème c’est géré) dans le destructeur.
    3) Dans le constructeur de copie ou opérateur d’affectation on libérera les pointeurs avant de les réaffecter ; et surtout ne pas toucher à l’objet source


  9. #9
    Nouveau membre du Club
    Profil pro
    Inscrit en
    Novembre 2005
    Messages
    39
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Novembre 2005
    Messages : 39
    Points : 31
    Points
    31
    Par défaut
    Citation Envoyé par farscape
    re,
    Il ne faut pas sous estimer l’utilisation d’un objet.

    Pour un objet avec allocations mémoire on devra faire :
    1) pointeur d’allocation mis a nul dans le(s) constructeur(s).
    2) delete des différents pointeurs d’allocations systématique (si le pointeur est null pas de problème c’est géré).dans le destructeur
    3) Dans le constructeur de copie ou opérateur d’affectation on libérera les pointeurs avant de les réaffecter ; et surtout ne pas toucher à l’objet source

    re

    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
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    CTeleSSMS
    --------------------------------------------------------------------------------
     
      constructeur de recopie
     
    ********************************************************************************/
     
    CTeleSSMS::CTeleSSMS(const CTeleSSMS & t)
    {
    	int i;
    	this->id = t.id;
    	this->liste = t.liste;
    	this->onInit = t.onInit;
    	this->m_modem_init_ok = t.m_modem_init_ok;
    	this->g_DCB = t.g_DCB;
    	this->m_iEtatCom = t.m_iEtatCom;
    	this->g_hcom = t.g_hcom;
    	this->m_transition = t.m_transition;
    	this->m_recopie = t.m_recopie;
     
     
    	for(i=0; i<MAX_ACTION_MEDIA; i++)
    	{
    		this->m_lastaction[i].m_idcc = t.m_lastaction[i].m_idcc;
    		this->m_lastaction[i].m_idaction = t.m_lastaction[i].m_idaction;
    		this->m_lastaction[i].m_code = t.m_lastaction[i].m_code;
    		this->m_lastaction[i].m_idactionmedia = t.m_lastaction[i].m_idactionmedia;
    		this->m_lastaction[i].m_idmedia = t.m_lastaction[i].m_idmedia;
    		this->m_lastaction[i].m_idtypeaction = t.m_lastaction[i].m_idtypeaction;
    		this->m_lastaction[i].demande = t.m_lastaction[i].demande;
    		this->m_lastaction[i].niveau = t.m_lastaction[i].niveau;
    		this->m_lastaction[i].m_now = t.m_lastaction[i].m_now;
    		this->m_lastaction[i].m_acquit = t.m_lastaction[i].m_acquit;
    		this->m_lastaction[i].m_action = t.m_lastaction[i].m_action;
    		strcpy(this->m_lastaction[i].telephone,t.m_lastaction[i].telephone);
    	}
     
    	//normalement on part dans l'operateur =  de la class CdefaultGestionnaire
    	delete this->m_default;
    	this->m_default = new CDefaultGestionnaire("TELESSMS");
     
    	this->m_default = t.m_default;
     
    	strcpy(this->m_default->m_filename, t.m_default->m_filename);
    	strcpy(this->m_default->m_db_user, t.m_default->m_db_user);
    	strcpy(this->m_default->m_db_passwd, t.m_default->m_db_passwd);
    	strcpy(this->m_default->m_db_name, t.m_default->m_db_name);
    	strcpy(this->m_default->m_db_host, t.m_default->m_db_host);
    	strcpy(this->m_default->m_log_filename, t.m_default->m_log_filename);	
     
    /*** normalement lut dans le fichier ini au moment du new CDefaultGestionnaire ***/
    	this->m_default->m_val_timer = t.m_default->m_val_timer;
    	this->m_default->m_type_media = t.m_default->m_type_media;
    /*********************************************************************************/
     
    	for(i=0; i<4; i++)
    	{
    		strcpy(this->ts_numero_telephone[i],t.ts_numero_telephone[i]);
    	}
     
    	this->ts_tempo_rappel = t.ts_tempo_rappel;
     
    }
    si je delete avant de l'allouer comme tu me le dit, il plante 'Access Violation'.

  10. #10
    Rédacteur
    Avatar de farscape
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Novembre 2003
    Messages
    9 055
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Alpes Maritimes (Provence Alpes Côte d'Azur)

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Novembre 2003
    Messages : 9 055
    Points : 17 323
    Points
    17 323
    Par défaut
    j'ai modifié mon post j'avais oublié de preciser dans le destructeur.
    sinon cette portion de code n'est pas bonne:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
     
    // 1
    delete this->m_default;
    // 2
       this->m_default = new CDefaultGestionnaire("TELESSMS");
    // 3
       this->m_default = t.m_default;
    la ligne 1 ne doit pas planter sauf si m_default (qui doit etre un pointeur ?)
    n'est pas initialisé a null dans le(s) constructeur.
    ligne 2 ok .
    ligne 3 tu perds l'adresse allouée en 2 -> memory leaks....

  11. #11
    Nouveau membre du Club
    Profil pro
    Inscrit en
    Novembre 2005
    Messages
    39
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Novembre 2005
    Messages : 39
    Points : 31
    Points
    31
    Par défaut
    Citation Envoyé par farscape
    j'ai modifié mon post j'avais oublié de preciser dans le destructeur.
    sinon cette portion de code n'est pas bonne:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
     
    // 1
    delete this->m_default;
    // 2
       this->m_default = new CDefaultGestionnaire("TELESSMS");
    // 3
       this->m_default = t.m_default;
    la ligne 1 ne doit pas planter sauf si m_default (qui doit etre un pointeur ?)
    n'est pas initialisé a null dans le(s) constructeur.
    ligne 2 ok .
    ligne 3 tu perds l'adresse allouée en 2 -> memory leaks....
    exacte pas vue le 3
    par contre il n'est pas init a NULL dans les constructeur il y a un new d'effectuer, mais quand on rentre dans la fonction il n'est pas init il vaut : 0xcccccc.

    je suis perdu un peut la.

    en tout cas merci de m'aider

  12. #12
    Rédacteur
    Avatar de farscape
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Novembre 2003
    Messages
    9 055
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Alpes Maritimes (Provence Alpes Côte d'Azur)

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Novembre 2003
    Messages : 9 055
    Points : 17 323
    Points
    17 323
    Par défaut
    quand je dis le constructeur je ne parle pas du constructeur de copie ,
    mais des constructeurs de base ou celui par defaut....

  13. #13
    Nouveau membre du Club
    Profil pro
    Inscrit en
    Novembre 2005
    Messages
    39
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Novembre 2005
    Messages : 39
    Points : 31
    Points
    31
    Par défaut
    Citation Envoyé par farscape
    quand je dis le constructeur je ne parle pas du constructeur de copie ,
    mais des constructeurs de base ou celui par defaut....
    on parle bien des meme constructeur.

  14. #14
    Nouveau membre du Club
    Profil pro
    Inscrit en
    Novembre 2005
    Messages
    39
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Novembre 2005
    Messages : 39
    Points : 31
    Points
    31
    Par défaut
    CA Y ESTTTTTTTTTTT


    un grand merci a toi pour ton aide

    alors je recapitule:
    j'ai supprimer le 3;
    j'ai remis le delete this->m_default;
    et la quand on rentre dans la recopie ca marcheeeeeeeeee

    je suis trop comptant
    un tres grand merci a toi

    Merci Merci Merci

  15. #15
    Nouveau membre du Club
    Profil pro
    Inscrit en
    Novembre 2005
    Messages
    39
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Novembre 2005
    Messages : 39
    Points : 31
    Points
    31
    Par défaut
    pour info voila ce qui a etait modifié:
    donc pas de delete dans la recopie, car on pas pas par le constructeur
    et effectivement le delete dans l'operateur d'affectation qui lui est deja init.




    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
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    /*******************************************************************************
    CTeleSSMS
    --------------------------------------------------------------------------------
     
      constructeur de recopie
     
    ********************************************************************************/
     
    CTeleSSMS::CTeleSSMS(const CTeleSSMS & t)
    {
    	int i;
    	this->id = t.id;
    	this->liste = t.liste;
    	this->onInit = t.onInit;
    	this->m_modem_init_ok = t.m_modem_init_ok;
    	this->g_DCB = t.g_DCB;
    	this->m_iEtatCom = t.m_iEtatCom;
    	this->g_hcom = t.g_hcom;
    	this->m_transition = t.m_transition;
    	this->m_recopie = t.m_recopie;
     
     
    	for(i=0; i<MAX_ACTION_MEDIA; i++)
    	{
    		this->m_lastaction[i].m_idcc = t.m_lastaction[i].m_idcc;
    		this->m_lastaction[i].m_idaction = t.m_lastaction[i].m_idaction;
    		this->m_lastaction[i].m_code = t.m_lastaction[i].m_code;
    		this->m_lastaction[i].m_idactionmedia = t.m_lastaction[i].m_idactionmedia;
    		this->m_lastaction[i].m_idmedia = t.m_lastaction[i].m_idmedia;
    		this->m_lastaction[i].m_idtypeaction = t.m_lastaction[i].m_idtypeaction;
    		this->m_lastaction[i].demande = t.m_lastaction[i].demande;
    		this->m_lastaction[i].niveau = t.m_lastaction[i].niveau;
    		this->m_lastaction[i].m_now = t.m_lastaction[i].m_now;
    		this->m_lastaction[i].m_acquit = t.m_lastaction[i].m_acquit;
    		this->m_lastaction[i].m_action = t.m_lastaction[i].m_action;
    		strcpy(this->m_lastaction[i].telephone,t.m_lastaction[i].telephone);
    	}
     
    	//delete this->m_default; <= si activer acces violation
    	this->m_default = new CDefaultGestionnaire("TELESSMS");
     
    	strcpy(this->m_default->m_filename, t.m_default->m_filename);
    	strcpy(this->m_default->m_db_user, t.m_default->m_db_user);
    	strcpy(this->m_default->m_db_passwd, t.m_default->m_db_passwd);
    	strcpy(this->m_default->m_db_name, t.m_default->m_db_name);
    	strcpy(this->m_default->m_db_host, t.m_default->m_db_host);
    	strcpy(this->m_default->m_log_filename, t.m_default->m_log_filename);	
     
    /*** normalement lut dans le fichier ini au moment du new CDefaultGestionnaire ***/
    	this->m_default->m_val_timer = t.m_default->m_val_timer;
    	this->m_default->m_type_media = t.m_default->m_type_media;
    /*********************************************************************************/
     
    	for(i=0; i<4; i++)
    	{
    		strcpy(this->ts_numero_telephone[i],t.ts_numero_telephone[i]);
    	}
     
    	this->ts_tempo_rappel = t.ts_tempo_rappel;
     
    }
     
     
    CTeleSSMS::operator= (CTeleSSMS & t)
    {
    	int i;
    	this->id = t.id;
    	this->liste = t.liste;
    	this->onInit = t.onInit;
    	this->m_modem_init_ok = t.m_modem_init_ok;
    	this->g_DCB = t.g_DCB;
    	this->m_iEtatCom = t.m_iEtatCom;
    	this->g_hcom = t.g_hcom;
    	this->m_transition = t.m_transition;
    	this->m_recopie = t.m_recopie;
     
     
    	for(i=0; i<MAX_ACTION_MEDIA; i++)
    	{
    		this->m_lastaction[i].m_idcc = t.m_lastaction[i].m_idcc;
    		this->m_lastaction[i].m_idaction = t.m_lastaction[i].m_idaction;
    		this->m_lastaction[i].m_code = t.m_lastaction[i].m_code;
    		this->m_lastaction[i].m_idactionmedia = t.m_lastaction[i].m_idactionmedia;
    		this->m_lastaction[i].m_idmedia = t.m_lastaction[i].m_idmedia;
    		this->m_lastaction[i].m_idtypeaction = t.m_lastaction[i].m_idtypeaction;
    		this->m_lastaction[i].demande = t.m_lastaction[i].demande;
    		this->m_lastaction[i].niveau = t.m_lastaction[i].niveau;
    		this->m_lastaction[i].m_now = t.m_lastaction[i].m_now;
    		this->m_lastaction[i].m_acquit = t.m_lastaction[i].m_acquit;
    		this->m_lastaction[i].m_action = t.m_lastaction[i].m_action;
    		strcpy(this->m_lastaction[i].telephone,t.m_lastaction[i].telephone);
    	}
     
    	delete this->m_default; //ici OK car affectation donc deja init
    	this->m_default = new CDefaultGestionnaire("TELESSMS");
     
    	strcpy(this->m_default->m_filename, t.m_default->m_filename);
    	strcpy(this->m_default->m_db_user, t.m_default->m_db_user);
    	strcpy(this->m_default->m_db_passwd, t.m_default->m_db_passwd);
    	strcpy(this->m_default->m_db_name, t.m_default->m_db_name);
    	strcpy(this->m_default->m_db_host, t.m_default->m_db_host);
    	strcpy(this->m_default->m_log_filename, t.m_default->m_log_filename);	
     
    /*** normalement lut dans le fichier ini au moment du new CDefaultGestionnaire ***/
    	this->m_default->m_val_timer = t.m_default->m_val_timer;
    	this->m_default->m_type_media = t.m_default->m_type_media;
    /*********************************************************************************/
     
    	for(i=0; i<4; i++)
    	{
    		strcpy(this->ts_numero_telephone[i],t.ts_numero_telephone[i]);
    	}
     
    	this->ts_tempo_rappel = t.ts_tempo_rappel;
     
    };

  16. #16
    Rédacteur
    Avatar de farscape
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Novembre 2003
    Messages
    9 055
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Alpes Maritimes (Provence Alpes Côte d'Azur)

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Novembre 2003
    Messages : 9 055
    Points : 17 323
    Points
    17 323
    Par défaut
    un conseil utilise des objets CString ou string pour stocker tes chaines ,
    ça t'eviteras de possibles problemes avec les char sur les strcpy : debordement memoire.
    le code sera plus securisé.
    autre remarque le code d'un constructeur de copie ou d'un operateur d'affectation est tres similaire tu peux une seule fonction qui fait le boulot
    comme dans :
    http://c.developpez.com/faq/vc/?page...HowToSerialize
    fonction copyfrom.

  17. #17
    Nouveau membre du Club
    Profil pro
    Inscrit en
    Novembre 2005
    Messages
    39
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Novembre 2005
    Messages : 39
    Points : 31
    Points
    31
    Par défaut
    j'ai utiliser tres peut de char*, effectivement j'utilise bcp plus de CString et de string plus facile a manipuler je trouve et surtout extensible

    ici j'utilise des char* car ils sont issus des GetPrivateProfileString donc ca m'evite une convertion.

    en tout cas un grand merci a toi je comprend un peu mieux mon probleme

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Réponses: 21
    Dernier message: 01/09/2011, 09h56
  2. Probleme fuite memoire sprintf + threads
    Par Invité dans le forum Bibliothèque standard
    Réponses: 9
    Dernier message: 23/09/2008, 10h07
  3. probleme de mémoire?
    Par dams78 dans le forum GTK+ avec C & C++
    Réponses: 12
    Dernier message: 24/02/2006, 13h52
  4. [langage] Problème de mémoire
    Par And_the_problem_is dans le forum Langage
    Réponses: 6
    Dernier message: 22/07/2003, 16h17
  5. [swing] probleme de memoire
    Par leBigouden dans le forum AWT/Swing
    Réponses: 6
    Dernier message: 23/05/2003, 14h19

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo