Skip to contentSkip to conversation

Guard against inserting the same provider twice

PATCH Superseded [email protected] 2 participants 2 messages Jan 15

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Guard against inserting the same provider twice

From: Eugene Loh <[email protected]>

Add a safety net to dt_provider_create(), to check if a specified provider has already been inserted.

This also requires a corresponding change in dt_provider_lookup(), so that it will work even if no providers have yet been inserted.

---
 libdtrace/dt_provider.c | 6 ++++++
 1 file changed, 6 insertions(+)
libdtrace/dt_provider.c +6 -0
index 848fdc132..9d75225fa 100644
@@ -114,6 +114,8 @@ dt_provider_lookup(dtrace_hdl_t *dtp, const char *name)
 		return NULL;
 
 	strcpy(tmpl.desc.dtvd_name, name);
+	if (dtp->dt_provs == NULL)
+		return NULL;
 	return dt_htab_lookup(dtp->dt_provs, &tmpl);
 }
 
@@ -124,6 +126,10 @@ dt_provider_create(dtrace_hdl_t *dtp, const char *name,
 {
 	dt_provider_t *pvp;
 
+	pvp = dt_provider_lookup(dtp, name);
+	if (pvp)
+		return pvp;
+
 	if ((pvp = dt_zalloc(dtp, sizeof(dt_provider_t))) == NULL)
 		goto nomem;
 
Signature · 1 line
2.47.3
#1 lore raw

Minor nit below...

Quoted 18 lines · On Thu, Jan 15, 2026 at 05:22:51PM -0500, [email protected] wrote:

From: Eugene Loh <[email protected]>

Add a safety net to dt_provider_create(), to check if a specified provider has already been inserted.

This also requires a corresponding change in dt_provider_lookup(), so that it will work even if no providers have yet been inserted.

---
 libdtrace/dt_provider.c | 6 ++++++
 1 file changed, 6 insertions(+)
libdtrace/dt_provider.c +0 -0
index 848fdc132..9d75225fa 100644

libdtrace/dt_provider.c dt_provider_lookup(dtrace_hdl_t *dtp, const char *name) · line 118

Quoted 5 lines
libdtrace/dt_provider.c +2 -0
@@ -114,6 +114,8 @@ dt_provider_lookup(dtrace_hdl_t *dtp, const char *name)
 		return NULL;
 
 	strcpy(tmpl.desc.dtvd_name, name);
+	if (dtp->dt_provs == NULL)
+		return NULL;

This should be moved as the first conditional in the function, because we want to return immediately if there is no dtp->dt_provs yet.

Quoted 17 lines
libdtrace/dt_provider.c +4 -0
 	return dt_htab_lookup(dtp->dt_provs, &tmpl);
 }
 
@@ -124,6 +126,10 @@ dt_provider_create(dtrace_hdl_t *dtp, const char *name,
 {
 	dt_provider_t *pvp;
 
+	pvp = dt_provider_lookup(dtp, name);
+	if (pvp)
+		return pvp;
+
 	if ((pvp = dt_zalloc(dtp, sizeof(dt_provider_t))) == NULL)
 		goto nomem;
 
Signature · 1 line
2.47.3