Skip to content

Commit 5bdebad

Browse files
committed
Infer fixes for com.wolfssl.WolfSSLX509Name
1 parent afc0f68 commit 5bdebad

1 file changed

Lines changed: 19 additions & 10 deletions

File tree

src/java/com/wolfssl/WolfSSLX509Name.java

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ public class WolfSSLX509Name {
3131
/* Lock around active state */
3232
private final Object stateLock = new Object();
3333

34+
/* Lock around x509NamePtr pointer access */
35+
private final Object x509NameLock = new Object();
36+
3437
/* Cache name elements in Java before pushing through JNI, for easier
3538
* retrieval from getXXX() methods */
3639
private String countryName = null;
@@ -97,8 +100,10 @@ protected long getNativeX509NamePtr() throws IllegalStateException {
97100

98101
confirmObjectIsActive();
99102

100-
/* TODO lock around x509NamePtr */
101-
return this.x509NamePtr;
103+
/* TODO lock around x509NamePtr for caller use */
104+
synchronized (x509NameLock) {
105+
return this.x509NamePtr;
106+
}
102107
}
103108

104109
/**
@@ -122,9 +127,11 @@ private synchronized void addEntryByTxt(String field, String entry)
122127
"addEntryByTxt()");
123128
}
124129

125-
ret = X509_NAME_add_entry_by_txt(this.x509NamePtr, field,
126-
MBSTRING_UTF8, entry.getBytes(),
127-
entry.getBytes().length, -1, 0);
130+
synchronized (x509NameLock) {
131+
ret = X509_NAME_add_entry_by_txt(this.x509NamePtr, field,
132+
MBSTRING_UTF8, entry.getBytes(),
133+
entry.getBytes().length, -1, 0);
134+
}
128135

129136
if (ret != WolfSSL.SSL_SUCCESS) {
130137
throw new WolfSSLException("Error setting " + field + " into " +
@@ -507,12 +514,14 @@ public synchronized void free() {
507514
/* already freed, just return */
508515
return;
509516
}
510-
511-
/* free native resources */
512-
X509_NAME_free(this.x509NamePtr);
513517

514-
this.active = false;
515-
this.x509NamePtr = 0;
518+
synchronized (x509NameLock) {
519+
/* free native resources */
520+
X509_NAME_free(this.x509NamePtr);
521+
522+
this.active = false;
523+
this.x509NamePtr = 0;
524+
}
516525
}
517526
}
518527

0 commit comments

Comments
 (0)