Browse code

-changed strdup to pkg_malloc, valgrind disliked strlen(strdup'ed memory)

Tomas Mandys authored on 08/02/2006 21:11:51
Showing 1 changed files
... ...
@@ -100,7 +100,6 @@ int set_mod_param_regex(char* regex, char* name, modparam_t type, void* val)
100 100
 				} else {
101 101
 					val2 = val;
102 102
 				}
103
-
104 103
 				DBG("set_mod_param_regex: found <%s> in module %s [%s]\n", name, t->exports->name, t->path);
105 104
 				if (param_type & PARAM_USE_FUNC) {
106 105
 					if ( ((param_func_t)(ptr))(param_type, val2) < 0) {
... ...
@@ -112,12 +111,23 @@ int set_mod_param_regex(char* regex, char* name, modparam_t type, void* val)
112 111
 				else {
113 112
 					switch(PARAM_TYPE_MASK(param_type)) {
114 113
 						case PARAM_STRING:
115
-							*((char**)ptr) = strdup((char*)val2);
114
+							*((char**)ptr) = pkg_malloc(strlen((char*)val2)+1);
115
+							if (!*((char**)ptr)) {
116
+								LOG(L_ERR, "set_mod_param_regex(): No memory left\n");
117
+								return -1;
118
+							}
119
+							strcpy(*((char**)ptr), (char*)val2);
116 120
 							break;
117 121
 
118 122
 						case PARAM_STR:
119
-							((str*)ptr)->s = strdup(((str*)val2)->s);
120
-							((str*)ptr)->len = ((str*)ptr)->s?strlen(((str*)ptr)->s):0;
123
+							((str*)ptr)->s = pkg_malloc(((str*)val2)->len+1);
124
+							if (!((str*)ptr)->s) {
125
+								LOG(L_ERR, "set_mod_param_regex(): No memory left\n");
126
+								return -1;
127
+							}
128
+							memcpy(((str*)ptr)->s, ((str*)val2)->s, ((str*)val2)->len);
129
+							((str*)ptr)->len = ((str*)val2)->len;
130
+							((str*)ptr)->s[((str*)ptr)->len] = 0;
121 131
 							break;
122 132
 
123 133
 						case PARAM_INT: