package/ar7-atm: move configuration in submenu
[openwrt.git] / package / hotplug2 / patches / 100-env_memleak.patch
1 --- a/action.c
2 +++ b/action.c
3 @@ -31,6 +31,30 @@ static void action_dumb(const struct set
4 }
5
6 /**
7 + * Creates a "key=value" string from the given key and value
8 + *
9 + * @1 Key
10 + * @2 Value
11 + *
12 + * Returns: Newly allocated string in "key=value" form
13 + *
14 + */
15 +static char* alloc_env(const char *key, const char *value) {
16 + size_t keylen, vallen;
17 + char *combined;
18 +
19 + keylen = strlen(key);
20 + vallen = strlen(value) + 1;
21 +
22 + combined = xmalloc(keylen + vallen + 1);
23 + memcpy(combined, key, keylen);
24 + combined[keylen] = '=';
25 + memcpy(&combined[keylen + 1], value, vallen);
26 +
27 + return combined;
28 +}
29 +
30 +/**
31 * Choose what action should be taken according to passed settings.
32 *
33 * @1 Hotplug settings
34 @@ -41,16 +65,25 @@ static void action_dumb(const struct set
35 */
36 void action_perform(struct settings_t *settings, struct uevent_t *event) {
37 int i;
38 + char **env;
39 +
40 + env = xmalloc(sizeof(char *) * event->env_vars_c);
41 +
42 + for (i = 0; i < event->env_vars_c; i++) {
43 + env[i] = alloc_env(event->env_vars[i].key, event->env_vars[i].value);
44 + putenv(env[i]);
45 + }
46
47 - for (i = 0; i < event->env_vars_c; i++)
48 - setenv(event->env_vars[i].key, event->env_vars[i].value, 1);
49 -
50 if (settings->dumb == 0) {
51 ruleset_execute(&settings->rules, event, settings);
52 } else {
53 action_dumb(settings, event);
54 }
55
56 - for (i = 0; i < event->env_vars_c; i++)
57 + for (i = 0; i < event->env_vars_c; i++) {
58 unsetenv(event->env_vars[i].key);
59 + free(env[i]);
60 + }
61 +
62 + free(env);
63 }
This page took 0.041558 seconds and 5 git commands to generate.