@@ -183,11 +183,11 @@ static uint8_t *parse_char_class(const uint8_t *pat, size_t *pos)
183183{
184184 unsigned char range_start = 0 ;
185185 int hasprev = 0 ;
186- uint8_t * bitmap = cli_malloc ( 32 ) ;
187- if (! bitmap ) {
188- cli_errmsg ( "parse_char_class: Unable to allocate memory for bitmap\n" );
189- return NULL ;
190- }
186+ uint8_t * bitmap = NULL ;
187+
188+ CLI_MALLOC ( bitmap , 32 ,
189+ cli_errmsg ( "parse_char_class: Unable to allocate memory for bitmap\n" )) ;
190+
191191 if (pat [* pos ] == '^' ) {
192192 memset (bitmap , 0xFF , 32 ); /*match chars not in brackets*/
193193 ++ * pos ;
@@ -200,14 +200,15 @@ static uint8_t *parse_char_class(const uint8_t *pat, size_t *pos)
200200 unsigned char range_end ;
201201 unsigned int c ;
202202 if (0 == range_start ) {
203+ FREE (bitmap );
203204 cli_errmsg ("parse_char_class: range_start not initialized" );
204- return NULL ;
205+ goto done ;
205206 }
206207 ++ * pos ;
207208 if (pat [* pos ] == '[' )
208209 if (pat [* pos + 1 ] == '.' ) {
209210 /* collating sequence not handled */
210- free (bitmap );
211+ FREE (bitmap );
211212 /* we are parsing the regex for a
212213 * filter, be conservative and
213214 * tell the filter that anything could
@@ -225,7 +226,7 @@ static uint8_t *parse_char_class(const uint8_t *pat, size_t *pos)
225226 hasprev = 0 ;
226227 } else if (pat [* pos ] == '[' && pat [* pos ] == ':' ) {
227228 /* char class */
228- free (bitmap );
229+ FREE (bitmap );
229230 while (pat [* pos ] != ']' ) ++ * pos ;
230231 ++ * pos ;
231232 while (pat [* pos ] != ']' ) ++ * pos ;
@@ -237,6 +238,8 @@ static uint8_t *parse_char_class(const uint8_t *pat, size_t *pos)
237238 hasprev = 1 ;
238239 }
239240 } while (pat [* pos ] != ']' );
241+
242+ done :
240243 return bitmap ;
241244}
242245
@@ -253,7 +256,7 @@ static struct node *parse_regex(const uint8_t *p, size_t *last)
253256 right = parse_regex (p , last );
254257 v = make_node (alternate , v , right );
255258 if (!v ) {
256- destroy_tree (right );
259+ destroy_tree (right );
257260 return NULL ;
258261 }
259262 break ;
@@ -451,7 +454,7 @@ cl_error_t cli_regex2suffix(const char *pattern, regex_t *preg, suffix_callback
451454 size_t last = 0 ;
452455 int rc ;
453456
454- if (NULL == pattern ){
457+ if (NULL == pattern ) {
455458 cli_errmsg ("cli_regex2suffix: pattern can't be NULL" );
456459 rc = REG_INVARG ;
457460 goto done ;
@@ -471,10 +474,10 @@ cl_error_t cli_regex2suffix(const char *pattern, regex_t *preg, suffix_callback
471474 }
472475 return rc ;
473476 }
474- regex .nxt = NULL ;
477+ regex .nxt = NULL ;
475478 CLI_STRDUP (pattern , regex .pattern ,
476- cli_errmsg ("cli_regex2suffix: unable to strdup regex.pattern" );
477- rc = REG_ESPACE );
479+ cli_errmsg ("cli_regex2suffix: unable to strdup regex.pattern" );
480+ rc = REG_ESPACE );
478481
479482 n = parse_regex (pattern , & last );
480483 if (!n ) {
0 commit comments