-
Notifications
You must be signed in to change notification settings - Fork 9
PHP: fix memory leaks and resource management issues #174
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -491,6 +491,10 @@ int valkey_glide_build_client_config_base(valkey_glide_php_common_constructor_pa | |
| } | ||
|
|
||
| _initialize_open_telemetry(params, is_cluster); | ||
| if (EG(exception)) { | ||
| valkey_glide_cleanup_client_config(config); | ||
| return FAILURE; | ||
| } | ||
| return SUCCESS; | ||
| } | ||
|
|
||
|
|
@@ -568,6 +572,27 @@ ZEND_GET_MODULE(valkey_glide) | |
| void free_valkey_glide_object(zend_object* object) { | ||
| valkey_glide_object* valkey_glide = VALKEY_GLIDE_PHP_GET_OBJECT(valkey_glide_object, object); | ||
|
|
||
| /* Free buffered batch commands if object is destroyed mid-batch */ | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should the buffered commands also be cleaned up when This also applies to |
||
| if (valkey_glide->buffered_commands) { | ||
| size_t i, j; | ||
| for (i = 0; i < valkey_glide->command_count; i++) { | ||
| struct batch_command* cmd = &valkey_glide->buffered_commands[i]; | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we need to free cmd as well? Or is buffered_commands allocated as one big array of batch_commands? |
||
| if (cmd->args) { | ||
| for (j = 0; j < cmd->arg_count; j++) { | ||
| if (cmd->args[j]) { | ||
| efree(cmd->args[j]); | ||
| } | ||
| } | ||
| efree(cmd->args); | ||
| } | ||
| if (cmd->arg_lengths) { | ||
| efree(cmd->arg_lengths); | ||
| } | ||
| } | ||
| efree(valkey_glide->buffered_commands); | ||
| valkey_glide->buffered_commands = NULL; | ||
| } | ||
|
|
||
| /* Free the Valkey Glide client if it exists */ | ||
| if (valkey_glide->glide_client) { | ||
| close_glide_client(valkey_glide->glide_client); | ||
|
|
@@ -1004,7 +1029,14 @@ PHP_METHOD(ValkeyGlide, __destruct) { | |
| /* {{{ proto boolean ValkeyGlide::close() | ||
| */ | ||
| PHP_METHOD(ValkeyGlide, close) { | ||
| /* TODO: Implement ValkeyGlide close */ | ||
| valkey_glide_object* valkey_glide = | ||
| VALKEY_GLIDE_PHP_ZVAL_GET_OBJECT(valkey_glide_object, getThis()); | ||
|
|
||
| if (valkey_glide->glide_client) { | ||
| close_glide_client(valkey_glide->glide_client); | ||
| valkey_glide->glide_client = NULL; | ||
| } | ||
|
|
||
| RETURN_TRUE; | ||
| } | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -454,8 +454,10 @@ int execute_sort_command(zval* object, int argc, zval* return_value, zend_class_ | |
| /* Free the argument arrays */ | ||
| efree(args); | ||
| efree(args_len); | ||
| efree(offset_str); | ||
| efree(count_str); | ||
| if (offset_str) | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Isn't efree(NULL) a no-op? Why add these if statements for just these two? |
||
| efree(offset_str); | ||
| if (count_str) | ||
| efree(count_str); | ||
|
|
||
|
|
||
| /* Process the result */ | ||
|
|
@@ -545,8 +547,10 @@ int execute_sort_ro_command(zval* object, int argc, zval* return_value, zend_cla | |
| /* Free the argument arrays */ | ||
| efree(args); | ||
| efree(args_len); | ||
| efree(offset_str); | ||
| efree(count_str); | ||
| if (offset_str) | ||
| efree(offset_str); | ||
| if (count_str) | ||
| efree(count_str); | ||
|
|
||
|
|
||
| int ret_val = 0; | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this set route->data.key_route.key to NULL so it doesn't get double-freed? Do we need to clean up anything else on route, or clean up route itself?