Skip to content

Commit ffd2dd3

Browse files
committed
fix: prevent dangling segments
1 parent 7b3a8e0 commit ffd2dd3

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

agent/lib_mongodb.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,7 @@ NR_PHP_WRAPPER(nr_mongodb_operation_after) {
191191
zval* database = NULL;
192192
zval* server = NULL;
193193
zval* this_var = NULL;
194+
bool discard_segment = false;
194195
nr_datastore_instance_t instance = {
195196
.host = NULL,
196197
.port_path_or_id = NULL,
@@ -216,6 +217,7 @@ NR_PHP_WRAPPER(nr_mongodb_operation_after) {
216217
if (!nr_php_object_instanceof_class(this_var, this_klass)) {
217218
nrl_verbosedebug(NRL_FRAMEWORK, "%s: operation is not %s", __func__,
218219
this_klass);
220+
discard_segment = true;
219221
goto leave;
220222
}
221223

@@ -235,9 +237,12 @@ NR_PHP_WRAPPER(nr_mongodb_operation_after) {
235237
nr_mongodb_get_host_and_port_path_or_id(server, &instance.host,
236238
&instance.port_path_or_id);
237239

238-
nr_segment_datastore_end(&auto_segment, &params);
239-
240240
leave:
241+
if (discard_segment) {
242+
nr_segment_discard(&auto_segment);
243+
} else {
244+
nr_segment_datastore_end(&auto_segment, &params);
245+
}
241246
nr_php_arg_release(&server);
242247
nr_php_scope_release(&this_var);
243248
nr_free(instance.host);

0 commit comments

Comments
 (0)