1
0
mirror of git://sourceware.org/git/lvm2.git synced 2024-12-21 13:34:40 +03:00

libdm: avoid leak if dm_task_set_* fn called again

(Mikulas)
This commit is contained in:
Alasdair G Kergon 2013-09-18 01:13:06 +01:00
parent a3a5f58c21
commit a0ca2c11ee
3 changed files with 5 additions and 0 deletions

View File

@ -1,5 +1,6 @@
Version 1.02.80 - Version 1.02.80 -
================================== ==================================
Free any previously-set string if a dm_task_set_* function is called again.
Do not allow passing empty new name for dmsetup rename. Do not allow passing empty new name for dmsetup rename.
Display any output returned by 'dmsetup message'. Display any output returned by 'dmsetup message'.
Add dm_task_get_message_response to libdevmapper. Add dm_task_get_message_response to libdevmapper.

View File

@ -785,6 +785,7 @@ int dm_task_set_newuuid(struct dm_task *dmt, const char *newuuid)
newuuid = mangled_uuid; newuuid = mangled_uuid;
} }
dm_free(dmt->newname);
if (!(dmt->newname = dm_strdup(newuuid))) { if (!(dmt->newname = dm_strdup(newuuid))) {
log_error("dm_task_set_newuuid: strdup(%s) failed", newuuid); log_error("dm_task_set_newuuid: strdup(%s) failed", newuuid);
return 0; return 0;
@ -796,6 +797,7 @@ int dm_task_set_newuuid(struct dm_task *dmt, const char *newuuid)
int dm_task_set_message(struct dm_task *dmt, const char *message) int dm_task_set_message(struct dm_task *dmt, const char *message)
{ {
dm_free(dmt->message);
if (!(dmt->message = dm_strdup(message))) { if (!(dmt->message = dm_strdup(message))) {
log_error("dm_task_set_message: strdup failed"); log_error("dm_task_set_message: strdup failed");
return 0; return 0;
@ -814,6 +816,7 @@ int dm_task_set_sector(struct dm_task *dmt, uint64_t sector)
int dm_task_set_geometry(struct dm_task *dmt, const char *cylinders, const char *heads, int dm_task_set_geometry(struct dm_task *dmt, const char *cylinders, const char *heads,
const char *sectors, const char *start) const char *sectors, const char *start)
{ {
dm_free(dmt->geometry);
if (dm_asprintf(&(dmt->geometry), "%s %s %s %s", if (dm_asprintf(&(dmt->geometry), "%s %s %s %s",
cylinders, heads, sectors, start) < 0) { cylinders, heads, sectors, start) < 0) {
log_error("dm_task_set_geometry: sprintf failed"); log_error("dm_task_set_geometry: sprintf failed");

View File

@ -720,6 +720,7 @@ int dm_task_set_newname(struct dm_task *dmt, const char *newname)
newname = mangled_name; newname = mangled_name;
} }
dm_free(dmt->newname);
if (!(dmt->newname = dm_strdup(newname))) { if (!(dmt->newname = dm_strdup(newname))) {
log_error("dm_task_set_newname: strdup(%s) failed", newname); log_error("dm_task_set_newname: strdup(%s) failed", newname);
return 0; return 0;