J'ai un petit soucis de la libération d'une chaîne avec free(). Le code devenant vraiment très gros les erreurs potentiels les plus banale peuvent se glisser dedans mais là je vois pas trop, je vais vous montrer ce que je peut pour pas trop vous embrouiller

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
DECLSPEC void b_string_free (BString ** p_str)
{
   if (p_str && *p_str)
   {
      b_object_unref (p_str);

      if ((*p_str)->sz_string)
      {
         b_free ((*p_str)->sz_string);
         (*p_str)->sz_string = NULL;
      }

      b_free (*p_str);
      *p_str = NULL;
   }
}
Cette ligne pose problème, l'objet est créé ainsi (je vais vous montrer une partie du cheminement dans l'ordre) :
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
DECLSPEC BString * b_string_new_with_text (const char * s_str)
{
   BString * p_new = NULL;
 
   if (s_str)
   {
      p_new = b_string_new ();
 
      if (p_new)
      {
         p_new->sz_string = b_string_dup (s_str);
 
         if (p_new->sz_string)
            p_new->len = strlen (p_new->sz_string);
         else
            b_string_free (&p_new);
      }
   }
 
   return p_new;
}
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
DECLSPEC BString * b_string_new (void)
{
   BString * p_new = b_malloc (sizeof (* p_new));
 
   if (p_new)
   {
      b_object_initializer (
         p_new,
         B_STRING_TYPE,
         B_STRING_TYPE,
         B_OBJECT_REFERENCEABLE);
 
      p_new->len              = 0;
      p_new->sz_string        = NULL;
 
      p_new->destroy_func     = b_string_free;
 
      b_object_ref ((BObject **)&p_new);
   }
 
   return p_new;
}
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
static char * b_string_dup (const char * s_str)
{
   char * s = NULL;
 
   if (s_str)
   {
      s = b_malloc (strlen (s_str) + 1);
 
      if (s)
         strcpy (s, s_str);
   }
 
   return s;
}
Si jamais vous voyez une anomalie quelque part...