diff --git a/src/slurmctld/agent.c b/src/slurmctld/agent.c
index 426f507d525558d63bd7b7973945b1126d8fa02b..e0bf9359c2e544f20dd60aac81194dcc652c9dbb 100644
--- a/src/slurmctld/agent.c
+++ b/src/slurmctld/agent.c
@@ -905,7 +905,9 @@ static void _slurmctld_free_job_launch_msg(batch_job_launch_msg_t * msg)
 			xfree(msg->environment[0]);
 			xfree(msg->environment);
 		}
+#ifdef HAVE_BGL
 		xfree(msg->bgl_part_id);
+#endif
 		slurm_free_job_launch_msg(msg);
 	}
 }