@@ -772,8 +772,6 @@ enum lsof_error lsof_select_process_regex(struct lsof_context *ctx, char *x) {
772772 MALLOC_S xl ;
773773 char * xp = (char * )NULL ;
774774 enum lsof_error ret = LSOF_SUCCESS ;
775- lsof_rx_t * new_rx ;
776- int new_cmdrx_cap ;
777775
778776 if (!ctx || ctx -> frozen ) {
779777 return LSOF_ERROR_INVALID_ARGUMENT ;
@@ -897,13 +895,7 @@ enum lsof_error lsof_select_process_regex(struct lsof_context *ctx, char *x) {
897895 /*
898896 * More CmdRx[] space must be assigned.
899897 */
900- new_cmdrx_cap = NCmdRxA + 32 ;
901- xl = (MALLOC_S )(new_cmdrx_cap * sizeof (lsof_rx_t ));
902- if (CmdRx )
903- new_rx = (lsof_rx_t * )realloc ((MALLOC_P * )CmdRx , xl );
904- else
905- new_rx = (lsof_rx_t * )malloc (xl );
906- if (!new_rx ) {
898+ if (grow_array ((void * * )& CmdRx , & NCmdRxA , sizeof (lsof_rx_t ), 32 )) {
907899 if (ctx -> err ) {
908900 (void )fprintf (ctx -> err , "%s: no space for regexp: " , Pn );
909901 safestrprt (x , ctx -> err , 1 );
@@ -912,8 +904,6 @@ enum lsof_error lsof_select_process_regex(struct lsof_context *ctx, char *x) {
912904 ret = LSOF_ERROR_NO_MEMORY ;
913905 goto cleanup ;
914906 }
915- CmdRx = new_rx ;
916- NCmdRxA = new_cmdrx_cap ;
917907 }
918908 i = NCmdRxU ;
919909 /*
@@ -977,15 +967,7 @@ enum lsof_error lsof_select_pid_pgid(struct lsof_context *ctx, int32_t id,
977967 * Allocate table table space.
978968 */
979969 if (* size >= * cap ) {
980- * cap += 10 ;
981- if (!(* sel ))
982- * sel = (struct int_lst * )malloc (
983- (MALLOC_S )(sizeof (struct int_lst ) * (* cap )));
984- else
985- * sel = (struct int_lst * )realloc (
986- (MALLOC_P * )(* sel ),
987- (MALLOC_S )(sizeof (struct int_lst ) * (* cap )));
988- if (!(* sel )) {
970+ if (grow_array ((void * * )sel , cap , sizeof (struct int_lst ), 10 )) {
989971 if (ctx -> err ) {
990972 (void )fprintf (ctx -> err , "%s: no space for %d process%s IDs" , Pn ,
991973 * cap , is_pid ? "" : " group" );
@@ -1061,13 +1043,7 @@ enum lsof_error lsof_select_uid_login(struct lsof_context *ctx, uint32_t uid,
10611043 * Allocate space for User IDentifier.
10621044 */
10631045 if (Nuid >= Mxuid ) {
1064- Mxuid += 10 ;
1065- len = (MALLOC_S )(Mxuid * sizeof (struct seluid ));
1066- if (!Suid )
1067- Suid = (struct seluid * )malloc (len );
1068- else
1069- Suid = (struct seluid * )realloc ((MALLOC_P * )Suid , len );
1070- if (!Suid ) {
1046+ if (grow_array ((void * * )& Suid , & Mxuid , sizeof (struct seluid ), 10 )) {
10711047 if (ctx -> err ) {
10721048 (void )fprintf (ctx -> err , "%s: no space for UIDs" , Pn );
10731049 }
0 commit comments