This is the Variational Problem with free end-time and one proceeds like this:
$$\delta S= \int_{t_i}^{t_f+\delta t_f} L \left(q+\delta q,\dot{q}+\delta \dot{q},t\right) dt - \int_{t_i}^{t_f} L \left(q, \dot{q}, t\right) dt$$
After several transformations and integration by parts one finally gets the usual Euler-Lagrange diff eq plus a boundary condition involving $\delta t_f$:
$$0 = L(q, \dot{q}, t) \delta t_f + \frac{\partial L}{\partial \dot{q}}(\delta q_f - \dot{q} \delta t_f)$$
Derivation steps:
a. Expand the first integral in a Taylor series and keep terms of 1st order and splitting the limits of integration (and doing any cancelations):
$$
\delta S=
\int_{t_f}^{t_f+\delta{t_f}} \left[ L + \frac{\partial{L}}{\partial{q}}\delta{q} + \frac{\partial{L}}{\partial{\dot{q}}}\delta{\dot{q}} \right] dt +
\int_{t_i}^{t_f} \left[ \frac{\partial{L}}{\partial{q}}\delta{q} + \frac{\partial{L}}{\partial{\dot{q}}}\delta{\dot{q}} \right] dt
$$
b. The total variation consists of 2 variations; $\delta{q}$ and $\delta{t_f}$. Integrating over a small interval i.e $[t_f, t_f + \delta{t_f}]$ is effectively equivalent to multiplication by $\delta{t_f}$:
$$
\delta S=
\delta{t_f} \left[ L + \frac{\partial{L}}{\partial{q}}\delta{q} + \frac{\partial{L}}{\partial{\dot{q}}}\delta{\dot{q}} \right] +
\int_{t_i}^{t_f} \left[ \frac{\partial{L}}{\partial{q}}\delta{q} + \frac{\partial{L}}{\partial{\dot{q}}}\delta{\dot{q}} \right] dt
$$
c. Terms like $\delta{t_f}\delta{q}$ or $\delta{t_f}\delta{\dot{q}}$ are 2nd order variations and can be dropped:
$$
\delta S=
\delta{t_f} L +
\int_{t_i}^{t_f} \left[ \frac{\partial{L}}{\partial{q}}\delta{q} + \frac{\partial{L}}{\partial{\dot{q}}}\delta{\dot{q}} \right] dt
$$
d. Integration by parts yields a usual Euler-Lagrange diff eq. plus the boundary condition.
e. On the boundary condition at time $t_f$ one has:
Total variation of $q$ at $t_f$ is
$$\delta{q_f} = \delta{q(t_f)} + (\dot{q} + \delta{\dot{q}})\delta{t_f} = \delta{q(t_f)} + \dot{q}\delta{t_f}$$
or
$$\delta{q(t_f)} = \delta{q_f} - \dot{q}\delta{t_f}$$
Hint for @Y2H:
The total variation at the boundary $\delta{q_f}$ is simply the sum of the path and time variations at the boundary (since these can be considered as independent variations), ie $(\delta{q(t_f)}) + (q(t_f+\delta{t_f})+\delta{q(t_f+\delta{t_f})}-q(t_f)-\delta{q(t_f)})$ and the latter can be decomposed (up to 1st order variations) as $(\dot{q}(t_f) + \delta{\dot{q}(t_f)})\delta{t_f}$
PS: There has been a long time since posted this answer and I dont have my notes handy, but hope the above give you a hint.
PS2: Here are some synoptic lecture notes on generalised calculus of variations with free end points
$$\int_{t1}^{t2} \left( \frac{\partial L}{\partial q}\delta q+ \frac{\partial L}{\partial \dot q}\delta \dot q- \frac{\partial L}{\partial q} \dot q \delta t- \frac{\partial L}{\partial \dot q} \ddot q \delta t + \frac{\partial L}{\partial t} \delta t \right) dt $$
– user50482 Jun 17 '14 at 01:21