vserver 1.9.5.x5
[linux-2.6.git] / drivers / acpi / utilities / utcopy.c
index f04e81a..0b366d3 100644 (file)
@@ -5,7 +5,7 @@
  *****************************************************************************/
 
 /*
- * Copyright (C) 2000 - 2004, R. Byron Moore
+ * Copyright (C) 2000 - 2005, R. Byron Moore
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -424,23 +424,21 @@ acpi_ut_copy_esimple_to_isimple (
                break;
 
        default:
-               /*
-                * Whatever other type -- it is not supported
-                */
+               /* All other types are not supported */
+
                return_ACPI_STATUS (AE_SUPPORT);
        }
 
 
-       switch (external_object->type) {
-
        /* Must COPY string and buffer contents */
 
+       switch (external_object->type) {
        case ACPI_TYPE_STRING:
 
                internal_object->string.pointer =
                        ACPI_MEM_CALLOCATE ((acpi_size) external_object->string.length + 1);
                if (!internal_object->string.pointer) {
-                       return_ACPI_STATUS (AE_NO_MEMORY);
+                       goto error_exit;
                }
 
                ACPI_MEMCPY (internal_object->string.pointer,
@@ -456,7 +454,7 @@ acpi_ut_copy_esimple_to_isimple (
                internal_object->buffer.pointer =
                        ACPI_MEM_CALLOCATE (external_object->buffer.length);
                if (!internal_object->buffer.pointer) {
-                       return_ACPI_STATUS (AE_NO_MEMORY);
+                       goto error_exit;
                }
 
                ACPI_MEMCPY (internal_object->buffer.pointer,
@@ -479,6 +477,11 @@ acpi_ut_copy_esimple_to_isimple (
 
        *ret_internal_object = internal_object;
        return_ACPI_STATUS (AE_OK);
+
+
+error_exit:
+       acpi_ut_remove_reference (internal_object);
+       return_ACPI_STATUS (AE_NO_MEMORY);
 }
 
 
@@ -747,7 +750,7 @@ acpi_ut_copy_ielement_to_ielement (
 
                        status = acpi_ut_copy_simple_object (source_object, target_object);
                        if (ACPI_FAILURE (status)) {
-                               return (status);
+                               goto error_exit;
                        }
 
                        *this_target_ptr = target_object;
@@ -781,8 +784,8 @@ acpi_ut_copy_ielement_to_ielement (
                        ACPI_MEM_CALLOCATE (((acpi_size) source_object->package.count + 1) *
                                         sizeof (void *));
                if (!target_object->package.elements) {
-                       ACPI_MEM_FREE (target_object);
-                       return (AE_NO_MEMORY);
+                       status = AE_NO_MEMORY;
+                       goto error_exit;
                }
 
                /*
@@ -802,6 +805,10 @@ acpi_ut_copy_ielement_to_ielement (
        }
 
        return (status);
+
+error_exit:
+       acpi_ut_remove_reference (target_object);
+       return (status);
 }