Commit 126a8ca3e96dea686f42fbf822d8cf519668e232

Authored by Georg Hopp
1 parent 5e596ad3

fixed various memory management issues detected with valgrind

... ... @@ -42,14 +42,13 @@ controllerSignupCreate(
42 42 {
43 43 Credential credential;
44 44 User user;
  45 + Uuid user_id;
45 46 char * response_data;
46 47
47 48 _controllerProcessUserCreateArgs(args, &user, &credential);
48 49
49   - if (0 == uuidCompare(
50   - uuidZero,
51   - applicationCreateUser(application, credential, user)))
52   - {
  50 + user_id = applicationCreateUser(application, credential, user);
  51 + if (0 == uuidCompare(uuidZero, user_id)) {
53 52 response_data = NULL;
54 53 } else {
55 54 applicationLogin(application, credential, session);
... ... @@ -58,6 +57,7 @@ controllerSignupCreate(
58 57
59 58 delete(credential);
60 59 delete(user);
  60 + delete(user_id);
61 61
62 62 return response_data;
63 63
... ...
... ... @@ -41,14 +41,13 @@ controllerUserCreate(
41 41 {
42 42 Credential credential;
43 43 User user;
  44 + Uuid user_id;
44 45 char * response_data;
45 46
46 47 _controllerProcessUserCreateArgs(args, &user, &credential);
47 48
48   - if (0 == uuidCompare(
49   - uuidZero,
50   - applicationCreateUser(application, credential, user)))
51   - {
  49 + user_id = applicationCreateUser(application, credential, user);
  50 + if (0 == uuidCompare(uuidZero, user_id)) {
52 51 response_data = NULL;
53 52 } else {
54 53 response_data = controllerCurrentuserRead(application, session, NULL);
... ... @@ -56,6 +55,7 @@ controllerUserCreate(
56 55
57 56 delete(credential);
58 57 delete(user);
  58 + delete(user_id);
59 59
60 60 return response_data;
61 61 }
... ...
... ... @@ -39,16 +39,17 @@ controllerUserUpdate(
39 39 Session session,
40 40 Hash args)
41 41 {
  42 + Uuid user_id;
  43 +
42 44 if (! _controllerUpdateUserFromArgs(args, &(session->user))) {
43 45 return NULL;
44 46 }
45 47
46   - if (0 == uuidCompare(
47   - uuidZero,
48   - applicationUpdateUser(application, session->user)))
49   - {
  48 + user_id = applicationUpdateUser(application, session->user);
  49 + if (0 == uuidCompare(uuidZero, user_id)) {
50 50 return NULL;
51 51 }
  52 + delete(user_id);
52 53
53 54 return controllerCurrentuserRead(application, session, NULL);
54 55 }
... ...
... ... @@ -62,6 +62,8 @@ applicationCreateUser(
62 62 return uuidZero;
63 63 }
64 64
  65 + MEM_FREE(user_serialized);
  66 +
65 67 if (! applicationUpdatePassword(this, cred, user)) {
66 68 /**
67 69 * \todo
... ...
... ... @@ -120,9 +120,12 @@ applicationLogin(
120 120 break;
121 121 }
122 122
  123 + delete(search);
123 124 return TRUE;
124 125 }
125 126
  127 + delete(search);
  128 +
126 129 return FALSE;
127 130 }
128 131
... ...
... ... @@ -48,8 +48,6 @@ applicationUpdatePassword(
48 48 unsigned char * hash = hash_data+SALT_SIZE;
49 49 Uuid index;
50 50
51   - index = indexUuid(user, this->user_namespace);
52   -
53 51 if (FALSE == hash_pw(
54 52 CRED_PWD(cred).pass,
55 53 CRED_PWD(cred).npass,
... ... @@ -61,12 +59,14 @@ applicationUpdatePassword(
61 59 memcpy(hash_data, salt, SALT_SIZE);
62 60 MEM_FREE(salt);
63 61
  62 + index = indexUuid(user, this->user_namespace);
64 63 storageUpdate(
65 64 this->passwords,
66 65 (char *)(index->uuid).value,
67 66 sizeof((index->uuid).value),
68 67 (char *)hash_data,
69 68 SALT_SIZE + HASH_SIZE);
  69 + delete(index);
70 70
71 71 return TRUE;
72 72 }
... ...
... ... @@ -61,6 +61,8 @@ applicationUpdateUser(
61 61 return uuidZero;
62 62 }
63 63
  64 + MEM_FREE(user_serialized);
  65 +
64 66 return index;
65 67 }
66 68
... ...
... ... @@ -67,7 +67,7 @@ configCtor(void * _this, va_list * params)
67 67 key++;
68 68 }
69 69
70   - if ('#' == *key) {
  70 + if ('#' == *key || 0 == *key) {
71 71 continue;
72 72 }
73 73
... ...
... ... @@ -54,7 +54,7 @@ configValueCtor(void * _this, va_list * params)
54 54 {
55 55 this->type = CONFIG_VALUE_STRING;
56 56 (this->value).string = memMalloc(nvalue-1);
57   - (this->value).string[nvalue-1] = '\0';
  57 + (this->value).string[nvalue-2] = '\0';
58 58 memcpy((this->value).string, value+1, nvalue-2);
59 59 this->nvalue = nvalue;
60 60 } else {
... ...
Please register or login to post a comment