If the demurrer is sustained, and no amendment of the accusatory pleading is permitted, or, in case an amendment is permitted, no amendment is made or amended pleading is filed within the time fixed therefor, the action shall be dismissed, and, except as provided in Section 1010, the court must order, if the defendant is in custody, that he be discharged or if he has been admitted to bail, that his bail be exonerated, or, if money or other property has been deposited instead of bail for his appearance, that such money or other property be refunded to him or to the person or persons found by the court to have deposited such money or other property on his behalf.
Ca. Pen. Code § 1008