diff --git a/regen.sh b/regen.sh
index 7652568584a9a4373f0660e6ff57c139049ab027..58c900ced968b12a3410926dd1c204ae21f1e806 100755
--- a/regen.sh
+++ b/regen.sh
@@ -42,10 +42,15 @@ if [ -z "$root" ]; then
   die "cannot find root of $PKG"
 fi
 
+remove_dirs=
+trap 'rm -rf $remove_dirs' EXIT
+
 if [ -z "$PROTOBUF" ]; then
-  protodir=$(mktemp -d -t regen-cds-proto.XXXXXX)
-  git clone -q $PROTO_REPO $protodir &
-  trap 'rm -rf $protodir' EXIT
+  proto_repo_dir=$(mktemp -d -t regen-cds-proto.XXXXXX)
+  git clone -q $PROTO_REPO $proto_repo_dir &
+  remove_dirs="$proto_repo_dir"
+  # The protoc include directory is actually the "src" directory of the repo.
+  protodir="$proto_repo_dir/src"
 else
   protodir="$PROTOBUF"
 fi
@@ -53,7 +58,7 @@ fi
 if [ -z "$GOOGLEAPIS" ]; then
   apidir=$(mktemp -d -t regen-cds-api.XXXXXX)
   git clone -q $API_REPO $apidir &
-  trap 'rm -rf $apidir' EXIT
+  remove_dirs="$remove_dirs $apidir"
 else
   apidir="$GOOGLEAPIS"
 fi
@@ -70,3 +75,4 @@ echo 1>&2 "Checking that the libraries build..."
 go build -v ./...
 
 echo 1>&2 "All done!"
+