Is there an example of a scheme $X$ and $f\in \Gamma(X,\mathcal{O}_X)$ such that the map
$$\Gamma(X,\mathcal{O}_X)_f\rightarrow \mathcal{O}_X(X_f)$$ is not injective ?
Hartshorne II 2.16 b) states its injective under the assumption of quasi-compactness.
Notation:$X_f=\{x\in X|f_x\not \in \mathfrak{m}_x\}$.
Let $X_n=\operatorname{Spec} k[t]/t^n$, and consider $X=\coprod_{n>0} X_n$ with the global section $f=(t,t,\cdots)$. It is clear that the restriction of $f$ to any local ring is a nilpotent and therefore belongs to the maximal ideal, so $X_f=\emptyset$ and $\mathcal{O}_X(X_f)=0$. On the other hand, $\Gamma(X,\mathcal{O}_X)_f$ is nonzero: if $1=0$ in the localization, then we would necessarily have $f^m=0$ for some $m$, which doesn't happen (look at the restriction of $f$ to the local ring at $X_{m+1}$).