Browse Source

- port from opensips, commit 4977, 4988, credits to Dan Pascu
- move variable declaration, remove unneeded variable 'prefix'
- test for failure in memory allocation


git-svn-id: https://openser.svn.sourceforge.net/svnroot/openser/trunk@5365 689a6050-402a-0410-94f2-e92a70836424

Henning Westerholt 16 years ago
parent
commit
88dc2f06c9
1 changed files with 7 additions and 4 deletions
  1. 7 4
      lib/srdb1/db.c

+ 7 - 4
lib/srdb1/db.c

@@ -147,7 +147,7 @@ error:
  * \note on error mydbf will contain only 0s */
 int db_bind_mod(const str* mod, db_func_t* mydbf)
 {
-	char* tmp, *p;
+	char *name, *tmp, *p;
 	int len;
 	db_func_t dbf;
 	db_bind_api_f dbind;
@@ -166,9 +166,12 @@ int db_bind_mod(const str* mod, db_func_t* mydbf)
 		return 0;
 	}
 	// add the prefix
-	char * name = pkg_malloc(mod->len + 4);
-	char * prefix = "db_";
-	memcpy(name, prefix, 3);
+	name = pkg_malloc(mod->len + 4);
+	if (!name) {
+		LM_ERR("no private memory left\n");
+		return -1;
+	}
+	memcpy(name, "db_", 3);
 	memcpy(name+3, mod->s, mod->len);
 	name[mod->len+3] = 0;