(1) On adjudging the cancellation of an instrument, the court may require the party to whom such relief is granted, to restore, so far as may be any benefit which he may have received from the other party and to make any compensation to him which justice may require.
(2) Where a defendant successfully resists any suit on the ground--
(a) that the instrument sought to be enforced against him in the suit is voidable, the court may if the defendant has received any benefit under the instrument from the other party, require him to restore, so far as may be, such benefit to that party or to make compensation for it;
(b) that the agreement sought to be enforced against him in the suit is void by reason of his not having been competent to contract under section 11 of the Indian Contract Act, 1872 (9 of 1872), the court may, if the defendant has received any benefit under the agreement from the other party, require him to restore, so far as may be, such benefit to that party, to the extent to which he or his estate has benefited thereby.