Kaynağa Gözat

lib/srdb1: clone db url in db_id structure

Daniel-Constantin Mierla 11 yıl önce
ebeveyn
işleme
5457bcbc51
2 değiştirilmiş dosya ile 6 ekleme ve 2 silme
  1. 5 2
      lib/srdb1/db_id.c
  2. 1 0
      lib/srdb1/db_id.h

+ 5 - 2
lib/srdb1/db_id.c

@@ -239,12 +239,12 @@ struct db_id* new_db_id(const str* url, db_pooling_t pooling)
 		return 0;
 	}
 
-	ptr = (struct db_id*)pkg_malloc(sizeof(struct db_id));
+	ptr = (struct db_id*)pkg_malloc(sizeof(struct db_id) + url->len + 1);
 	if (!ptr) {
 		LM_ERR("no private memory left\n");
 		goto err;
 	}
-	memset(ptr, 0, sizeof(struct db_id));
+	memset(ptr, 0, sizeof(struct db_id)+url->len+1);
 
 	if (parse_db_url(ptr, url) < 0) {
 		LM_ERR("error while parsing database URL: '%.*s' \n", url->len, url->s);
@@ -254,6 +254,9 @@ struct db_id* new_db_id(const str* url, db_pooling_t pooling)
 	if (pooling == DB_POOLING_NONE) ptr->poolid = ++poolid;
 	else ptr->poolid = 0;
 	ptr->pid = my_pid();
+	ptr->url.len = url->len;
+	strncpy(ptr->url.s, url->s, url->len);
+	ptr->url.s[url->len] = '\0';
 
 	return ptr;
 

+ 1 - 0
lib/srdb1/db_id.h

@@ -35,6 +35,7 @@
 
 /** Structure representing a database ID */
 struct db_id {
+	str   url;           /**< full URL clone */
 	char* scheme;        /**< URL scheme */
 	char* username;      /**< Username, case sensitive */
 	char* password;      /**< Password, case sensitive */