Germany had to amend the law back in the day to make Open Source legal.
Before that it wasn't possible to forgoe payment and even now it's not possible in many cases.
as far as i know only the moral rights can not be given up, but i am unaware that there was an issue with giving away work for free.
There are lot of nuances what constitutes consideration, it varies by jurisdiction and also there is lot of common law ( i.e. based on judicial precedents ) that can be complicated and only experts could really could even a given opinion on that and only way to be really know is after that issue comes up in a case for first time in that jurisdiction.
Using Quebec's terminology by way of example, a contract where an advantage is given in exchange for rendering the obligation (so roughly a contract with consideration) is called an onerous contract, and most typical contracts for services fall into this category. The kind where one obligates oneself without receiving an advantage in return is called a gratuitous contract, and they classify gifts in this category.
https://de.m.wikipedia.org/wiki/Linux-Klausel
The referenced article is §32 UrhG
That would make any gift of copyrighted material invalid.