Commit 126a8ca3e96dea686f42fbf822d8cf519668e232

Authored by Georg Hopp
1 parent 5e596ad3

fixed various memory management issues detected with valgrind

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