The obligation of the surety is accessory to that of his principal; and, if the latter from any cause becomes extinct, the former shall cease of course, even though it is in judgment. If, however, the original contract of the principal was invalid from a disability to contract and this disability was known to the surety, he shall still be bound.