For the Republicans
I've addressed this in a previous answer, where I looked at the current RNC rules (pdf, hosting webpage). I'll quote from it here:
It's also worth looking at Rule 16(a)(2) (emphasis mine):
The Secretary of the Convention shall faithfully announce and record each delegate’s vote in accordance with the delegate’s obligation
under these rules, state law or state party rule. If any delegate
bound by these rules, state party rule or state law to vote for a
presidential candidate at the national convention demonstrates support
under Rule 40 for any person other than the candidate to whom he or
she is bound, such support shall not be recognized. Except as
provided for by state law or state party rule, no presidential
candidate shall have the power to remove a delegate.
The first part (before my bolding) means that the first vote is
entirely a formality, because anyone who doesn't vote in accordance with their bound vote is ignored. So the "faithless elector"
equivalent cannot happen at the Republican convention. The bolded
part is more interesting, however. It means that a candidate can't
get around their lack of Rule 40(b) support by suborning enough
delegates to get past the threshold - any such support is also
ignored.
For the Democrats
According to this article:
Democratic rules do not refer to bound delegates. The delegates are
seemingly only loosely pledged to a candidate based on the results of
the primaries and caucuses.
But that loose pledge is stronger than it would appear. In some
states, candidates hand-pick delegates and file their names with the
state or party. Any delegates the candidates win come from this list,
and so the bond between candidate and delegate is likely to be strong.
In general, pledged Democratic delegates are likely to be loyal to their candidate if that candidate is still viable and has not “released” the delegates to vote for another candidate.
This matches what I've been able to determine by reading the DNC rules (pdf), which (as far as I can tell) only says:
Delegates may vote for the candidate of their choice whether or not the name of such candidate was placed in nomination. Any vote cast other than a vote for a presidential candidate meeting the requirements of Article VI of this Call and Rule 12.K. of the 2016 Delegate Selection Rules shall be considered a vote for “Present.” [Section VIII(C)(7)(c), page 46 of the PDF]