You told him you had weed and and it sounds like you let him search your car. So yes, they did have the right to do that, you gave them permission. Unless a huge cloud of smoke poured out the window or you completely reaked like pot, you might have been able to get out of that one. Sorry i don't know the laws in texas, but you're not going to jail.