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 112
 				else {
113 113
 					switch(PARAM_TYPE_MASK(param_type)) {
114 114
 						case PARAM_STRING:
115
-							*((char**)ptr) = strdup((char*)val2);
115
+							*((char**)ptr) = pkg_malloc(strlen((char*)val2)+1);
116
+							if (!*((char**)ptr)) {
117
+								LOG(L_ERR, "set_mod_param_regex(): No memory left\n");
118
+								return -1;
119
+							}
120
+							strcpy(*((char**)ptr), (char*)val2);
116 121
 							break;
117 122
 
118 123
 						case PARAM_STR:
119
-							((str*)ptr)->s = strdup(((str*)val2)->s);
120
-							((str*)ptr)->len = ((str*)ptr)->s?strlen(((str*)ptr)->s):0;
124
+							((str*)ptr)->s = pkg_malloc(((str*)val2)->len+1);
125
+							if (!((str*)ptr)->s) {
126
+								LOG(L_ERR, "set_mod_param_regex(): No memory left\n");
127
+								return -1;
128
+							}
129
+							memcpy(((str*)ptr)->s, ((str*)val2)->s, ((str*)val2)->len);
130
+							((str*)ptr)->len = ((str*)val2)->len;
131
+							((str*)ptr)->s[((str*)ptr)->len] = 0;
121 132
 							break;
122 133
 
123 134
 						case PARAM_INT: