Added a null-safe strdup variant

This commit is contained in:
Martin Willi
2011-01-05 16:46:02 +01:00
parent b0892d094c
commit 1038d9fee5
7 changed files with 13 additions and 8 deletions
+1 -1
View File
@@ -536,7 +536,7 @@ child_cfg_t *child_cfg_create(char *name, lifetime_cfg_t *lifetime,
.destroy = _destroy,
},
.name = strdup(name),
.updown = updown ? strdup(updown) : NULL,
.updown = strdupnull(updown),
.hostaccess = hostaccess,
.mode = mode,
.start_action = start_action,
+1 -1
View File
@@ -682,7 +682,7 @@ peer_cfg_t *peer_cfg_create(char *name, u_int ike_version, ike_cfg_t *ike_cfg,
this->use_mobike = mobike;
this->dpd = dpd;
this->virtual_ip = virtual_ip;
this->pool = pool ? strdup(pool) : NULL;
this->pool = strdupnull(pool);
this->local_auth = linked_list_create();
this->remote_auth = linked_list_create();
this->refcount = 1;
@@ -235,7 +235,7 @@ METHOD(android_creds_t, set_username_password, void,
DESTROY_IF(this->user);
this->user = id->clone(id);
free(this->pass);
this->pass = password ? strdup(password) : NULL;
this->pass = strdupnull(password);
this->lock->unlock(this->lock);
}
+3 -3
View File
@@ -400,7 +400,7 @@ static void set_username_password(private_nm_creds_t *this, identification_t *id
DESTROY_IF(this->user);
this->user = id->clone(id);
free(this->pass);
this->pass = password ? strdup(password) : NULL;
this->pass = strdupnull(password);
this->lock->unlock(this->lock);
}
@@ -411,7 +411,7 @@ static void set_key_password(private_nm_creds_t *this, char *password)
{
this->lock->write_lock(this->lock);
free(this->keypass);
this->keypass = password ? strdup(password) : NULL;
this->keypass = strdupnull(password);
this->lock->unlock(this->lock);
}
@@ -423,7 +423,7 @@ static void set_pin(private_nm_creds_t *this, chunk_t keyid, char *pin)
this->lock->write_lock(this->lock);
free(this->keypass);
free(this->keyid.ptr);
this->keypass = pin ? strdup(pin) : NULL;
this->keypass = strdupnull(pin);
this->keyid = chunk_clone(keyid);
this->lock->unlock(this->lock);
}