@@ -163,28 +163,34 @@ static LTC_INLINE int s_x509_get_name_process(const ltc_asn1_list *set, st_oid_d
163163 return CRYPT_OK ;
164164}
165165
166+
166167#ifndef S_FREE
167168#define S_FREE
168- #define s_free (p ) s_free_((void*) p )
169- static LTC_INLINE void s_free_ (void * p )
169+ #define s_free (p ) s_free_((void**) &(p) )
170+ static LTC_INLINE void s_free_ (void * * p )
170171{
171- if (p == NULL ) {
172+ if (p == NULL || * p == NULL ) {
172173 return ;
173174 }
174- XFREE ((void * )p );
175+ XFREE (* p );
176+ * p = NULL ;
175177}
176178#endif
177179
178180#ifndef S_FREE_X509_STRING_ARRAY
179181#define S_FREE_X509_STRING_ARRAY
180- #define s_free_x509_string_array (s , n ) s_free_x509_string_array_((ltc_x509_string*)s , n)
181- static LTC_INLINE void s_free_x509_string_array_ (ltc_x509_string * strings , unsigned long num )
182+ #define s_free_x509_string_array (s , n ) s_free_x509_string_array_((ltc_x509_string**)&(s) , n)
183+ static LTC_INLINE void s_free_x509_string_array_ (ltc_x509_string * * strings_ , unsigned long num )
182184{
183185 unsigned long n ;
186+ ltc_x509_string * strings ;
187+ if (strings_ == NULL )
188+ return ;
189+ strings = * strings_ ;
184190 for (n = num ; n -- > 0 ;) {
185191 s_free (strings [n ].str );
186192 }
187- s_free ( strings );
193+ s_free_ (( void * * ) strings_ );
188194}
189195#endif
190196
@@ -333,7 +339,7 @@ static int s_x509_get_name(const ltc_asn1_list *seq, ltc_x509_name *name)
333339 name -> names = names ;
334340 name -> names_num = names_num ;
335341err_out :
336- if (err != CRYPT_OK && names != NULL ) {
342+ if (err != CRYPT_OK ) {
337343 s_free_x509_string_array (names , names_num );
338344 }
339345 XFREE (name_elements );
@@ -432,14 +438,10 @@ static int s_x509_get_validity(const ltc_asn1_list *seq, ltc_x509_validity *vali
432438 }
433439 return CRYPT_OK ;
434440err_out :
435- if (validity -> not_after .str ) {
441+ if (validity -> not_after .str )
436442 s_free (validity -> not_after .str );
437- validity -> not_after .str = NULL ;
438- }
439- if (validity -> not_before .str ) {
443+ if (validity -> not_before .str )
440444 s_free (validity -> not_before .str );
441- validity -> not_before .str = NULL ;
442- }
443445 return err ;
444446}
445447
@@ -691,8 +693,7 @@ void x509_free(const ltc_x509_certificate **cert)
691693 s_free (c -> signature .signature );
692694 s_free_x509_tbs_cert (& c -> tbs_certificate );
693695 der_free_sequence_flexi ((void * )c -> asn1 );
694- s_free (c );
695- * cert = NULL ;
696+ s_free_ ((void * * )cert );
696697}
697698
698699#undef st_oid_detail
0 commit comments