Author: byterock
Date: Fri Dec  7 07:53:15 2007
New Revision: 10386

Modified:
   dbd-oracle/trunk/dbdimp.c
   dbd-oracle/trunk/oci8.c

Log:
well Most of the leak fix.

Modified: dbd-oracle/trunk/dbdimp.c
==============================================================================
--- dbd-oracle/trunk/dbdimp.c   (original)
+++ dbd-oracle/trunk/dbdimp.c   Fri Dec  7 07:53:15 2007
@@ -290,7 +290,22 @@
     Safefree(fb_ary);
 }
 
-
+void
+fb_obj_free(fbh_obj_t *fb_obj)
+{
+    if (fb_obj->parmdp)
+           Safefree(fb_obj->parmdp);            
+       if (fb_obj->parmap)
+               Safefree(fb_obj->parmap);            
+       if (fb_obj->obj_ref)
+               Safefree(fb_obj->obj_ref);                      
+       if (fb_obj->obj_type)
+               Safefree(fb_obj->obj_type);         
+    if (fb_obj->fields)
+       Safefree(fb_obj->fields);
+    Safefree(fb_obj);
+       
+}
 /* ================================================================== */
 
 
@@ -3168,6 +3183,8 @@
     sv_free(fbh->name_sv);
     if (fbh->desc_h)
        OCIDescriptorFree_log(fbh->desc_h, fbh->desc_t);
+       if (fbh->obj)
+       fb_obj_free(fbh->obj);
 }
 
 void

Modified: dbd-oracle/trunk/oci8.c
==============================================================================
--- dbd-oracle/trunk/oci8.c     (original)
+++ dbd-oracle/trunk/oci8.c     Fri Dec  7 07:53:15 2007
@@ -1369,7 +1369,6 @@
 int
 get_object (SV *sth, AV *list, imp_fbh_t *fbh,fbh_obj_t *obj,OCIComplexObject 
*value){
        dTHX;
-
        sword           status;
        OCIIter         *itr = (OCIIter *) 0;
        dvoid           *element = (dvoid *) 0;
@@ -1383,9 +1382,6 @@
        sb4             index;
        fbh_obj_t       *fld;
 
-
-
-
        if (DBIS->debug >= 5) {
                PerlIO_printf(DBILOGFP, " getting attributes of object named  
%s with typecode=%d\n",obj->type_name,obj->typecode);
        }
@@ -1538,24 +1534,60 @@
 fetch_func_oci_object(SV *sth, imp_fbh_t *fbh,SV *dest_sv)
 {
     dTHX;
-   OCIComplexObject *item = (dvoid *) 0;
-
        if (DBIS->debug >= 4) {
                PerlIO_printf(DBILOGFP, " getting an embedded object named  %s 
with typecode=%d\n",fbh->obj->type_name,fbh->obj->typecode);
        }
 
+       fbh->obj->value=newAV();
+
        /*will return referance to an array of scalars*/
        if (!get_object(sth,fbh->obj->value,fbh,fbh->obj,fbh->obj->obj_value)){
                return 0;
        } else {
-               sv_setsv(dest_sv, newRV_noinc((SV *) fbh->obj->value));
-/*             list=NULL;*/
-
+               sv_setsv(dest_sv, sv_2mortal(newRV_noinc((SV *) 
fbh->obj->value)));
                return 1;
        }
 
 }
 
+int
+empty_oci_object(AV *values,fbh_obj_t *obj,int level){
+       dTHX;
+       int i;
+
+       for (i = 0; i < obj->field_count;i++){
+               fbh_obj_t *fld = &obj->fields[i];
+               if (fld->typecode == OCI_TYPECODE_OBJECT || fld->typecode == 
OCI_TYPECODE_VARRAY || fld->typecode == OCI_TYPECODE_TABLE || fld->typecode == 
OCI_TYPECODE_NAMEDCOLLECTION){
+
+                       empty_oci_object(fld->value,fld,level+1);
+                        av_clear(values);
+                        av_undef(values);
+       
+               } else {
+                 
+                   if (values && SvTYPE(values) <16){ 
+                               av_undef(values);
+                       }
+                       return 1;
+               }
+               
+    }
+    return 1;
+}
+int 
+fetch_cleanup_oci_object(SV *sth, imp_fbh_t *fbh){
+       dTHX;
+
+       if (fbh->obj){
+               if(fbh->obj->value){
+               empty_oci_object(fbh->obj->value,fbh->obj,0);
+               }
+       }
+       return 1;
+}
+
+
+
 static int                     /* --- Setup the row cache for this sth --- */
 sth_set_row_cache(SV *h, imp_sth_t *imp_sth, int max_cache_rows, int 
num_fields, int has_longs)
 {
@@ -1803,7 +1835,6 @@
 dump_struct(imp_sth_t *imp_sth,fbh_obj_t *obj,int level){
        dTHX;
        int i;
-
 /*dumps the contents of the current fbh->obj*/
 
        PerlIO_printf(DBILOGFP, " level=%d   type_name = 
%s\n",level,obj->type_name);
@@ -1831,6 +1862,10 @@
        return 1;
 }
 
+
+       
+
+
 int
 dbd_describe(SV *h, imp_sth_t *imp_sth)
 {
@@ -2018,6 +2053,7 @@
 
                fbh->ftype  = fbh->dbtype;  /*varray or alike */
                fbh->fetch_func = fetch_func_oci_object; /* need a new fetch 
function for it */
+               fbh->fetch_cleanup = fetch_cleanup_oci_object; /* clean up any 
AV  from the fetch*/
                fbh->desc_t = SQLT_NTY;
             if (!imp_sth->dschp){
                        OCIHandleAlloc_ok(imp_sth->envhp, &imp_sth->dschp, 
OCI_HTYPE_DESCRIBE, status);
@@ -2216,16 +2252,7 @@
     for(i=0; i < num_fields; ++i) {
                imp_fbh_t *fbh = &imp_sth->fbh[i];
                if (fbh->fetch_cleanup) fbh->fetch_cleanup(sth, fbh);
-
-               if (fbh->obj){
-                       if(fbh->obj->value){
-                       PerlIO_printf(DBILOGFP, "   hi mom 
%d\n",fbh->obj->value);
-                       av_undef(fbh->obj->value);
-                       } else {
-                               fbh->obj->value=newAV();
-                       }
-               }
-    }
+       }
 
     if (ora_fetchtest && DBIc_ROW_COUNT(imp_sth)>0) {
 

Reply via email to