popd before return / exit function
<p>In bash what is the proper way to <code>popd</code> before returning / exiting from a function?  For example,</p>

<pre><code>function fn () {
    pushd ~ &gt;/dev/null
    if [ $1 = $2 ]; then
        return 0;
    elif [ $2 = $3 ]; then
        return 1;
    else
        return 2;
    fi
    popd &gt;/dev/null
}
</code></pre>

<p>Am I supposed to write <code>popd</code> before each return?  Or, should I be doing this another way?</p>