0

I have variantinit immediately to variantClear like below,

VariantClear(&var); VariantInit(&var);

VariantInit is crashing in few places and few other places it's not crashing even though I have same sequence in both cases. What could be the reason for VariantInit to fail?

srajeshnkl
  • 883
  • 3
  • 16
  • 49
  • what have you put into `var` when it crashes ? tried a debugger? – AndersK Mar 11 '14 at 05:20
  • When debugged from windbg it shows after VariantClear also it contains some values, will it make issue? or what are the possibilities for VariantClear not to clear the var? – srajeshnkl Mar 11 '14 at 05:59
  • 2
    have you checked the return value of variantclear? – AndersK Mar 11 '14 at 06:40
  • Yes, VariantClear result is S_OK – srajeshnkl Mar 11 '14 at 07:40
  • 1
    Are you absolutely sure it's not `VariantClear` that crashes? It's difficult to imagine why `VariantInit` would crash. All it's doing is basically `var.vt = VT_EMPTY;` - not much can go wrong there. I can think of some pretty far-fetched scenarios: say, `var` is actually a global variable exported from a DLL, and the previous `VariantClear` call caused this DLL to be unloaded. On the other hand, it's pretty easy to get `VariantClear` to crash - just give it a variant with an invalid interface pointer (which in turn may be easily caused by a reference counting bug). – Igor Tandetnik Mar 11 '14 at 18:22

1 Answers1

0

You should call VariantInit() and then VariantClear()

Note: VariantClear() can crash if VARIANT is not a valid VARIANT.

Baum mit Augen
  • 49,044
  • 25
  • 144
  • 182
Peter
  • 1