Even if that was the case, I'll bet both of the authors would have been happy to see their books go into a library. Neither of them are currently available in Carnegie Library (our largest in Pittsburgh).
The author wouldn't get paid for a returned copy either. And publishers have very wide discretion over things like giving out freebie copies — in pretty much every standard publishing contract they control what happens to the books, not the author. An author is usually given a small amount of copies of the book (in O'Reilly's case 10) — beyond that what happens to all the rest is entirely in the publisher's hands.