@@ -408,11 +408,6 @@ func (imp *cimporter) doImportChildren() error {
408408 for i , c := range children {
409409 imp .children [i ].dt = st .Field (i ).Type
410410 if err := imp .children [i ].importChild (imp , c ); err != nil {
411- for j := 0 ; j < i ; j ++ {
412- if imp .children [j ].data != nil {
413- imp .children [j ].data .Release ()
414- }
415- }
416411 return err
417412 }
418413 }
@@ -436,11 +431,6 @@ func (imp *cimporter) doImportChildren() error {
436431 for i , c := range children {
437432 imp .children [i ].dt = dt .Fields ()[i ].Type
438433 if err := imp .children [i ].importChild (imp , c ); err != nil {
439- for j := 0 ; j < i ; j ++ {
440- if imp .children [j ].data != nil {
441- imp .children [j ].data .Release ()
442- }
443- }
444434 return err
445435 }
446436 }
@@ -449,11 +439,6 @@ func (imp *cimporter) doImportChildren() error {
449439 for i , c := range children {
450440 imp .children [i ].dt = dt .Fields ()[i ].Type
451441 if err := imp .children [i ].importChild (imp , c ); err != nil {
452- for j := 0 ; j < i ; j ++ {
453- if imp .children [j ].data != nil {
454- imp .children [j ].data .Release ()
455- }
456- }
457442 return err
458443 }
459444 }
@@ -484,8 +469,10 @@ func (imp *cimporter) doImportArr(src *CArrowArray) error {
484469 // memory that we have to track the lifetime of.
485470 defer func () {
486471 if imp .alloc .bufCount .Load () == 0 {
487- C .ArrowArrayRelease (imp .arr )
488- C .free (unsafe .Pointer (imp .arr ))
472+ if C .ArrowArrayIsReleased (imp .arr ) == 0 {
473+ C .ArrowArrayRelease (imp .arr )
474+ C .free (unsafe .Pointer (imp .arr ))
475+ }
489476 }
490477 }()
491478
@@ -495,20 +482,13 @@ func (imp *cimporter) doImportArr(src *CArrowArray) error {
495482// import is called recursively as needed for importing an array and its children
496483// in order to generate array.Data objects
497484func (imp * cimporter ) doImport () error {
498- // move the array from the src object passed in to the one referenced by
499- // this importer. That way we can set up a finalizer on the created
500- // arrow.ArrayData object so we clean up our Array's memory when garbage collected.
501- defer func (arr * CArrowArray ) {
502- // this should only occur in the case of an error happening
503- // during import, at which point we need to clean up the
504- // ArrowArray struct we allocated.
505- if imp .data == nil {
506- C .free (unsafe .Pointer (arr ))
507- }
508- }(imp .arr )
509-
510485 // import any children
511486 if err := imp .doImportChildren (); err != nil {
487+ for _ , c := range imp .children {
488+ if c .data != nil {
489+ c .data .Release ()
490+ }
491+ }
512492 return err
513493 }
514494
0 commit comments