The police are legally allowed to search a person and/or his vehicle whenever the police have made a legal arrest.  The justification for this search is police officer safety.  If the search precedes the arrest, it is an illegal search because the justification was not present at the time of the search.