summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorZdenek Kabelac <zkabelac@redhat.com>2012-02-10 13:56:19 +0000
committerZdenek Kabelac <zkabelac@redhat.com>2012-02-10 13:56:19 +0000
commit36ddbdbbe2082f8832218e70ae0d62f6e77c7a28 (patch)
treeaa47d276b1bfb594dc128adb102e4c2523a2ad1a
parentc046a59e7fe65d55c0cf2218e830563581396864 (diff)
downloadlvm2-36ddbdbbe2082f8832218e70ae0d62f6e77c7a28.tar.gz
lvm2-36ddbdbbe2082f8832218e70ae0d62f6e77c7a28.tar.xz
lvm2-36ddbdbbe2082f8832218e70ae0d62f6e77c7a28.zip
Return error for failing allocation
Fix case, where final strdup would have failed and it would miss to return failure for this case and return success and NULL pointer.
-rw-r--r--WHATS_NEW_DM1
-rw-r--r--libdm/libdm-string.c4
2 files changed, 4 insertions, 1 deletions
diff --git a/WHATS_NEW_DM b/WHATS_NEW_DM
index 5b42f777..2c4a70ff 100644
--- a/WHATS_NEW_DM
+++ b/WHATS_NEW_DM
@@ -1,5 +1,6 @@
Version 1.02.70 -
===================================
+ Return error for failing allocation in dm_asprintf().
Add missing test for failing allocation in dm_realloc() code.
Add test for memory allocation failures in regex matcher code.
Simplify dm_task_set_geometry() and use dm_asprintf().
diff --git a/libdm/libdm-string.c b/libdm/libdm-string.c
index 67eabf5d..d9b444c1 100644
--- a/libdm/libdm-string.c
+++ b/libdm/libdm-string.c
@@ -156,7 +156,9 @@ int dm_asprintf(char **result, const char *format, ...)
}
}
- *result = dm_strdup(buf);
+ if (!(*result = dm_strdup(buf)))
+ n = -2; /* return -1 */
+
dm_free(buf);
return n + 1;
}