How to fix curl error: "failed: Bad file descriptor"

How to fix an unexplained failure with the curl command:

curl -v https://github.com *   Trying 140.82.121.4:443... 
* connect to 140.82.121.4 port 443 failed: Bad file descriptor 
* Failed to connect to github.com port 443 after 24068 ms: Bad file descriptor 
* Closing connection 0

Turns out I somehow had a rule blocking all outbound network access for curl in my firewall software on macOS (Lulu).

The fix was simply to delete the offending firewall rule.