Skip to content

Commit d29d438

Browse files
committed
arnaud feedback
1 parent 79b987e commit d29d438

2 files changed

Lines changed: 16 additions & 56 deletions

File tree

ext/session/mod_mm.c

Lines changed: 13 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,7 @@ typedef struct ps_sd {
4646
} ps_sd;
4747

4848
typedef struct {
49-
GMappedFile *mm;
5049
GHashTable *hash;
51-
uint32_t hash_max;
52-
uint32_t hash_cnt;
5350
pid_t owner;
5451
} ps_mm;
5552

@@ -84,15 +81,11 @@ static ps_sd *ps_sd_new(ps_mm *data, zend_string *key)
8481

8582
g_hash_table_insert(data->hash, key, sd);
8683

87-
data->hash_cnt++;
88-
8984
return sd;
9085
}
9186

9287
static void ps_sd_destroy(ps_mm *data, zend_string *key, ps_sd *sd)
9388
{
94-
data->hash_cnt--;
95-
9689
if (sd->data) {
9790
g_free(sd->data);
9891
}
@@ -114,19 +107,12 @@ static gboolean ps_mm_key_equals(gconstpointer a, gconstpointer b) {
114107
return zend_string_equals((const zend_string *)a, (const zend_string *)b);
115108
}
116109

117-
static zend_result ps_mm_initialize(ps_mm *data, const char *path)
110+
static zend_result ps_mm_initialize(ps_mm *data)
118111
{
119112
data->owner = getpid();
120-
data->mm = g_mapped_file_new(path, TRUE, NULL);
121-
if (!data->mm) {
122-
return FAILURE;
123-
}
124-
125-
data->hash_cnt = 0;
126-
data->hash_max = 511;
127113
data->hash = g_hash_table_new(ps_mm_hash, ps_mm_key_equals);
128114
if (!data->hash) {
129-
g_mapped_file_unref(data->mm);
115+
php_error_docref(NULL, E_WARNING, "hash table created failed");
130116
return FAILURE;
131117
}
132118

@@ -168,50 +154,18 @@ static void ps_mm_destroy(ps_mm *data)
168154
g_hash_table_foreach_remove(data->hash, ps_mm_destroy_entry, NULL);
169155

170156
g_hash_table_destroy(data->hash);
171-
g_mapped_file_unref(data->mm);
172-
efree(data);
157+
pefree(data, true);
173158
}
174159

175160
PHP_MINIT_FUNCTION(ps_mm)
176161
{
177-
size_t save_path_len = ZSTR_LEN(PS(save_path));
178-
size_t mod_name_len = strlen(sapi_module.name);
179-
size_t euid_len;
180-
char *ps_mm_path, euid[30];
181-
zend_result ret;
182-
183-
ps_mm_instance = ecalloc(1, sizeof(*ps_mm_instance));
162+
ps_mm_instance = pecalloc(1, sizeof(*ps_mm_instance), true);
184163
if (!ps_mm_instance) {
185164
return FAILURE;
186165
}
187166

188-
if (!(euid_len = slprintf(euid, sizeof(euid), "%d", geteuid()))) {
189-
efree(ps_mm_instance);
190-
ps_mm_instance = NULL;
191-
return FAILURE;
192-
}
193-
194-
/* Directory + '/' + File + Module Name + Effective UID + \0 */
195-
ps_mm_path = emalloc(save_path_len + 1 + (sizeof(PS_MM_FILE) - 1) + mod_name_len + euid_len + 1);
196-
197-
memcpy(ps_mm_path, ZSTR_VAL(PS(save_path)), save_path_len);
198-
if (save_path_len && ZSTR_VAL(PS(save_path))[save_path_len - 1] != DEFAULT_SLASH) {
199-
ps_mm_path[save_path_len] = DEFAULT_SLASH;
200-
save_path_len++;
201-
}
202-
memcpy(ps_mm_path + save_path_len, PS_MM_FILE, sizeof(PS_MM_FILE) - 1);
203-
save_path_len += sizeof(PS_MM_FILE) - 1;
204-
memcpy(ps_mm_path + save_path_len, sapi_module.name, mod_name_len);
205-
save_path_len += mod_name_len;
206-
memcpy(ps_mm_path + save_path_len, euid, euid_len);
207-
ps_mm_path[save_path_len + euid_len] = '\0';
208-
209-
ret = ps_mm_initialize(ps_mm_instance, ps_mm_path);
210-
211-
efree(ps_mm_path);
212-
213-
if (ret == FAILURE) {
214-
free(ps_mm_instance);
167+
if (ps_mm_initialize(ps_mm_instance) == FAILURE) {
168+
pefree(ps_mm_instance, true);
215169
ps_mm_instance = NULL;
216170
return FAILURE;
217171
}
@@ -376,6 +330,13 @@ PS_CREATE_SID_FUNC(mm)
376330

377331
do {
378332
sid = php_session_create_id((void **)&data);
333+
if (!sid) {
334+
if (--maxfail < 0) {
335+
return NULL;
336+
} else {
337+
continue;
338+
}
339+
}
379340
/* Check collision */
380341
if (g_hash_table_contains(data->hash, sid) == SUCCESS) {
381342
if (sid) {
@@ -387,7 +348,6 @@ PS_CREATE_SID_FUNC(mm)
387348
}
388349
}
389350
} while(!sid);
390-
391351
return sid;
392352
}
393353

ext/session/session.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
#include "mod_files.h"
5151
#include "mod_user.h"
5252

53-
#ifdef HAVE_LIBMM
53+
#ifdef HAVE_LIBGLIB
5454
#include "mod_mm.h"
5555
#endif
5656

@@ -2966,7 +2966,7 @@ static PHP_MINIT_FUNCTION(session)
29662966
PS(session_status) = php_session_none;
29672967
REGISTER_INI_ENTRIES();
29682968

2969-
#ifdef HAVE_LIBMM
2969+
#ifdef HAVE_LIBGLIB
29702970
PHP_MINIT(ps_mm) (INIT_FUNC_ARGS_PASSTHRU);
29712971
#endif
29722972
php_session_rfc1867_orig_callback = php_rfc1867_callback;
@@ -2991,7 +2991,7 @@ static PHP_MSHUTDOWN_FUNCTION(session)
29912991
{
29922992
UNREGISTER_INI_ENTRIES();
29932993

2994-
#ifdef HAVE_LIBMM
2994+
#ifdef HAVE_LIBGLIB
29952995
PHP_MSHUTDOWN(ps_mm) (SHUTDOWN_FUNC_ARGS_PASSTHRU);
29962996
#endif
29972997

0 commit comments

Comments
 (0)