Docker Engine leaks memory when doing a docker exec on a non-existing command

Issue type
Memory leak

OS Version/build
Confirmed on two systems:
Linux stack03 4.4.0-72-generic #93-Ubuntu SMP Fri Mar 31 14:07:41 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux
Docker version 1.12.1, build 23cf638

Linux my_vm01 4.9.24-coreos #1 SMP Tue May 30 23:12:01 UTC 2017 x86_64 Intel® Core™ i7-4980HQ CPU @ 2.80GHz GenuineIntel GNU/Linux
Docker version 1.12.6, build d5236f0

Steps to reproduce

ID=$(docker run -d ubuntu sleep 1d)
while ! docker exec $ID foo; do echo “Ran”; done

Observe: Memory consumption of dockerd will keep going up until the system crashes (or the command is stopped).

Additional observation:
Running docker with debug will show an increasing amount of goroutines being allocated when running docker -D info, while exec commands are failing, as in this example:

docker info

Containers: 6
Running: 3
Paused: 0
Stopped: 3
Images: 2
Server Version: 1.12.6
Storage Driver: overlay
Backing Filesystem: extfs
Logging Driver: json-file
Cgroup Driver: cgroupfs
Volume: local
Network: overlay null host bridge
Swarm: inactive
Runtimes: runc
Default Runtime: runc
Security Options: seccomp selinux
Kernel Version: 4.9.24-coreos
Operating System: Container Linux by CoreOS 1353.8.0 (Ladybug)
OSType: linux
Architecture: x86_64
CPUs: 1
Total Memory: 996.8 MiB
Name: my_vm01
Docker Root Dir: /var/lib/docker
Debug Mode (client): true
Debug Mode (server): true
File Descriptors: 32
Goroutines: 2804
System Time: 2017-06-20T11:49:53.907049835Z
EventsListeners: 0
Insecure Registries:

This issue will not appear when the executed command is actually present