system/corennnnn
リビジョン | ba9ec54e6a8c5db3340179b985930a6c300e0a2a (tree) |
---|---|
日時 | 2016-12-09 16:22:10 |
作者 | Chih-Wei Huang <cwhuang@linu...> |
コミッター | Chih-Wei Huang |
ueventd: fix copied string not being freed
Unlike change Id0a5f711e33363082ba201afda6b26043998cb1c,
parse_subsystem and parse_line_subsystem hold points to memory
of the copied string which can't be freed.
To fix the issue, duplicate the strings to be hold.
Then we can parse the std::string data directly without
copying it.
Change-Id: I4dbf543de6880537b419e6c2344ee6a40ce378f1
@@ -113,7 +113,7 @@ static void *parse_subsystem(parse_state* state, int /*nargs*/, char** args) { | ||
113 | 113 | parse_error(state, "out of memory\n"); |
114 | 114 | return 0; |
115 | 115 | } |
116 | - s->name = args[1]; | |
116 | + s->name = strdup(args[1]); | |
117 | 117 | s->dirname = "/dev"; |
118 | 118 | list_add_tail(&subsystem_list, &s->slist); |
119 | 119 | return s; |
@@ -142,7 +142,7 @@ static void parse_line_subsystem(struct parse_state *state, int nargs, | ||
142 | 142 | |
143 | 143 | case K_dirname: |
144 | 144 | if (args[1][0] == '/') |
145 | - s->dirname = args[1]; | |
145 | + s->dirname = strdup(args[1]); | |
146 | 146 | else |
147 | 147 | parse_error(state, "dirname '%s' does not start with '/'\n", |
148 | 148 | args[1]); |
@@ -191,7 +191,7 @@ static void parse_line(struct parse_state *state, char **args, int nargs) | ||
191 | 191 | } |
192 | 192 | } |
193 | 193 | |
194 | -static void parse_config(const char *fn, const std::string& data) | |
194 | +static void parse_config(const char *fn, std::string& data) | |
195 | 195 | { |
196 | 196 | char *args[UEVENTD_PARSER_MAXARGS]; |
197 | 197 |
@@ -199,7 +199,7 @@ static void parse_config(const char *fn, const std::string& data) | ||
199 | 199 | parse_state state; |
200 | 200 | state.filename = fn; |
201 | 201 | state.line = 1; |
202 | - state.ptr = strdup(data.c_str()); // TODO: fix this code! | |
202 | + state.ptr = &data[0]; | |
203 | 203 | state.nexttoken = 0; |
204 | 204 | state.parse_line = parse_line_no_op; |
205 | 205 | for (;;) { |