Where does the word “stopgap” come from and What does stopgap mean?

One of the many meanings of to stop is “to dam, to plug up,” as in “to stop a leak,” or “to stop a drain.”

And a stopgap, even in its modern sense of some temporary measure to fill a need, is, both literally and figuratively, something to “stop” a “gap.”