In section $1.10$ of Shankar's Principles of Quantum Mechanics, it is stated that an operator $K$ satisfying $\langle x \vert K \vert x' \rangle = \langle x' \vert K \vert x \rangle ^*$ is not enough to guarantee that $\langle g \vert K \vert f \rangle = \langle f \vert K \vert g \rangle ^*$, and thus that $K$ is Hermitian. An explicit computation is given when $K = -iD$, in which it is found that the surface term $$ig^*(x) f(x) \bigg\vert_{a}^{b}$$ must vanish for $K$ to be Hermitian. I'm able to follow the derivation, however, I'm still not sure why said surface term has to vanish, since it seems to me I can show that without assuming such thing. Below is a sketch of what I mean:
Writing down $\vert f \rangle$ and $\vert g \rangle$ in my basis,
\begin{align} \vert f \rangle &= \int_{a}^{b} dx' \, f(x') \, \vert x' \rangle \, ; \\ \vert g \rangle &= \int_{a}^{b} dx \, g(x) \, \vert x \rangle \, . \end{align}
Then we have, \begin{align} \langle g \vert K \vert f \rangle &= \int_{a}^{b} \int_{a}^{b} dx \, dx' \, g^*(x) \, f(x') \, \langle x \vert K \vert x' \rangle \\ &= \int_{a}^{b} \int_{a}^{b} dx \, dx' \, g^*(x) \, f(x') \, \langle x' \vert K \vert x \rangle ^* \\ &= \left(\int_{a}^{b} \int_{a}^{b} dx \, dx' \, g(x) \, f^*(x') \, \langle x' \vert K \vert x \rangle \right)^* = \langle f \vert K \vert g \rangle ^*. \end{align} I guess my question is the following: is my derivation correct, and if it is, where am I assuming that such a surface term vanishes?