We present a quantum-state-diffusion equation to characterize the dynamics of a generic atomic system due to the coupling to a leaky cavity mode. As quantum resources, the population, the coherence and even the entanglement of the system would gradually leak out of the cavity. The effect from the leakage of the cavity-mode to the uncontrollable degrees of freedom, e.g. environment, is however not always negative to particular applications of these quantum resources. We investigate the competition between these two mechanisms in the framework of the non-Markovian open-quantum-system dynamics, where the leaky mode serves as a general two-layer bosonic environment. Numerical calculations based on our non-perturbative approach reveal a generation of quantum entanglement in the qubit system due to the coupling to a resonant leaky cavity.