Skip to content

Commit bdbc671

Browse files
committed
arnaud feedback
1 parent e10afba commit bdbc671

2 files changed

Lines changed: 16 additions & 55 deletions

File tree

ext/session/mod_mm.c

Lines changed: 13 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,7 @@ typedef struct ps_sd {
4444
} ps_sd;
4545

4646
typedef struct {
47-
GMappedFile *mm;
4847
GHashTable *hash;
49-
uint32_t hash_max;
50-
uint32_t hash_cnt;
5148
pid_t owner;
5249
} ps_mm;
5350

@@ -82,15 +79,11 @@ static ps_sd *ps_sd_new(ps_mm *data, zend_string *key)
8279

8380
g_hash_table_insert(data->hash, key, sd);
8481

85-
data->hash_cnt++;
86-
8782
return sd;
8883
}
8984

9085
static void ps_sd_destroy(ps_mm *data, zend_string *key, ps_sd *sd)
9186
{
92-
data->hash_cnt--;
93-
9487
if (sd->data) {
9588
g_free(sd->data);
9689
}
@@ -112,19 +105,12 @@ static gboolean ps_mm_key_equals(gconstpointer a, gconstpointer b) {
112105
return zend_string_equals((const zend_string *)a, (const zend_string *)b);
113106
}
114107

115-
static zend_result ps_mm_initialize(ps_mm *data, const char *path)
108+
static zend_result ps_mm_initialize(ps_mm *data)
116109
{
117110
data->owner = getpid();
118-
data->mm = g_mapped_file_new(path, TRUE, NULL);
119-
if (!data->mm) {
120-
return FAILURE;
121-
}
122-
123-
data->hash_cnt = 0;
124-
data->hash_max = 511;
125111
data->hash = g_hash_table_new(ps_mm_hash, ps_mm_key_equals);
126112
if (!data->hash) {
127-
g_mapped_file_unref(data->mm);
113+
php_error_docref(NULL, E_WARNING, "hash table created failed");
128114
return FAILURE;
129115
}
130116

@@ -166,50 +152,18 @@ static void ps_mm_destroy(ps_mm *data)
166152
g_hash_table_foreach_remove(data->hash, ps_mm_destroy_entry, NULL);
167153

168154
g_hash_table_destroy(data->hash);
169-
g_mapped_file_unref(data->mm);
170-
efree(data);
155+
pefree(data, true);
171156
}
172157

173158
PHP_MINIT_FUNCTION(ps_mm)
174159
{
175-
size_t save_path_len = ZSTR_LEN(PS(save_path));
176-
size_t mod_name_len = strlen(sapi_module.name);
177-
size_t euid_len;
178-
char *ps_mm_path, euid[30];
179-
zend_result ret;
180-
181-
ps_mm_instance = ecalloc(1, sizeof(*ps_mm_instance));
160+
ps_mm_instance = pecalloc(1, sizeof(*ps_mm_instance), true);
182161
if (!ps_mm_instance) {
183162
return FAILURE;
184163
}
185164

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

375329
do {
376330
sid = php_session_create_id((void **)&data);
331+
if (!sid) {
332+
if (--maxfail < 0) {
333+
return NULL;
334+
} else {
335+
continue;
336+
}
337+
}
377338
/* Check collision */
378339
if (g_hash_table_contains(data->hash, sid) == SUCCESS) {
379340
if (sid) {

ext/session/session.c

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

51-
#ifdef HAVE_LIBMM
51+
#ifdef HAVE_LIBGLIB
5252
#include "mod_mm.h"
5353
#endif
5454

@@ -2884,7 +2884,7 @@ static PHP_MINIT_FUNCTION(session)
28842884
PS(session_status) = php_session_none;
28852885
REGISTER_INI_ENTRIES();
28862886

2887-
#ifdef HAVE_LIBMM
2887+
#ifdef HAVE_LIBGLIB
28882888
PHP_MINIT(ps_mm) (INIT_FUNC_ARGS_PASSTHRU);
28892889
#endif
28902890
php_session_rfc1867_orig_callback = php_rfc1867_callback;
@@ -2909,7 +2909,7 @@ static PHP_MSHUTDOWN_FUNCTION(session)
29092909
{
29102910
UNREGISTER_INI_ENTRIES();
29112911

2912-
#ifdef HAVE_LIBMM
2912+
#ifdef HAVE_LIBGLIB
29132913
PHP_MSHUTDOWN(ps_mm) (SHUTDOWN_FUNC_ARGS_PASSTHRU);
29142914
#endif
29152915

0 commit comments

Comments
 (0)