diff --git a/engine/memobj.c b/engine/memobj.c index 7ebe4b8..b020c74 100644 --- a/engine/memobj.c +++ b/engine/memobj.c @@ -105,9 +105,11 @@ static sxi32 MemObjCallClassCastMethod( sxu32 nLen, /* Method name length */ ph7_value *pResult /* OUT: Store the return value of the magic method here */ ) { - ph7_class_method *pMethod; + ph7_class_method *pMethod = 0; /* Check if the method is available */ - pMethod = PH7_ClassExtractMethod(pThis->pClass, zMethod, nLen); + if(pThis) { + pMethod = PH7_ClassExtractMethod(pThis->pClass, zMethod, nLen); + } if(pMethod == 0) { /* No such method */ return SXERR_NOTFOUND; @@ -757,12 +759,14 @@ PH7_PRIVATE sxi32 PH7_MemObjStore(ph7_value *pSrc, ph7_value *pDest) { ph7_class_instance *pObj = 0; ph7_hashmap *pMap = 0; sxi32 rc; - if(pSrc->iFlags & MEMOBJ_HASHMAP) { - /* Increment reference count */ - ((ph7_hashmap *)pSrc->x.pOther)->iRef++; - } else if(pSrc->iFlags & MEMOBJ_OBJ) { - /* Increment reference count */ - ((ph7_class_instance *)pSrc->x.pOther)->iRef++; + if(pSrc->x.pOther) { + if(pSrc->iFlags & MEMOBJ_HASHMAP) { + /* Increment reference count */ + ((ph7_hashmap *)pSrc->x.pOther)->iRef++; + } else if(pSrc->iFlags & MEMOBJ_OBJ) { + /* Increment reference count */ + ((ph7_class_instance *)pSrc->x.pOther)->iRef++; + } } if(pDest->iFlags & MEMOBJ_HASHMAP) { pMap = (ph7_hashmap *)pDest->x.pOther; diff --git a/engine/oop.c b/engine/oop.c index 8e564bc..863be1b 100644 --- a/engine/oop.c +++ b/engine/oop.c @@ -717,10 +717,12 @@ static void PH7_ClassInstanceRelease(ph7_class_instance *pThis) { * If the reference count reaches zero,release the whole instance. */ PH7_PRIVATE void PH7_ClassInstanceUnref(ph7_class_instance *pThis) { - pThis->iRef--; - if(pThis->iRef < 1) { - /* No more reference to this instance */ - PH7_ClassInstanceRelease(&(*pThis)); + if(pThis) { + pThis->iRef--; + if(pThis->iRef < 1) { + /* No more reference to this instance */ + PH7_ClassInstanceRelease(&(*pThis)); + } } } /*