I agree, the search was illegal.
First of all, the officer had to find a pretense to pull out the magazine...which he may have done, for his ‘safety’.
But then - did he just happened to notice the round count? It was at night on the side of the road...I think he would have had to very deliberately used a flashlight to ‘inspect’ the magazine.
And there is the flaw in the law. Better yet, get a magazine that doesn’t have view holes. The officer can only strip the rounds out of the magazine, if he has probable cause to believe you have too many rounds...which he could never have.
I’m betting the gun was in the glove compartment to start with....and I’m also betting the magazine was separate....