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:
System1:
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

System2:
Linux my_vm01 4.9.24-coreos #1 SMP Tue May 30 23:12:01 UTC 2017 x86_64 Intel(R) 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
Plugins:
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
ID: 65R5:N264:TP4G:NO63:Q2EC:FGEK:RNVS:F42N:W66T:GHUM:ZK5M:WBMB
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
Registry: https://index.docker.io/v1/
Insecure Registries:
127.0.0.0/8

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