static void *virThreadHelper(void *data)
{
struct virThreadArgs *args = data;
- args->func(args->opaque);
+ struct virThreadArgs local = *args;
+
+ /* Free args early, rather than tying it up during the entire thread. */
VIR_FREE(args);
+ local.func(local.opaque);
return NULL;
}
return pthread_getspecific(l->key);
}
-void virThreadLocalSet(virThreadLocalPtr l, void *val)
+int virThreadLocalSet(virThreadLocalPtr l, void *val)
{
- pthread_setspecific(l->key, val);
+ int err = pthread_setspecific(l->key, val);
+ if (err) {
+ errno = err;
+ return -1;
+ }
+ return 0;
}
if (!event) {
return -1;
}
- virThreadLocalSet(&virCondEvent, event);
+ if (virThreadLocalSet(&virCondEvent, event) < 0) {
+ CloseHandle(event);
+ return -1;
+ }
}
virMutexLock(&c->lock);
return TlsGetValue(l->key);
}
-void virThreadLocalSet(virThreadLocalPtr l, void *val)
+int virThreadLocalSet(virThreadLocalPtr l, void *val)
{
- TlsSetValue(l->key, val);
+ return TlsSetValue(l->key, val) == 0 ? -1 : 0;
}
int virThreadLocalInit(virThreadLocalPtr l,
virThreadLocalCleanup c) ATTRIBUTE_RETURN_CHECK;
void *virThreadLocalGet(virThreadLocalPtr l);
-void virThreadLocalSet(virThreadLocalPtr l, void*);
+int virThreadLocalSet(virThreadLocalPtr l, void*) ATTRIBUTE_RETURN_CHECK;
# ifdef WIN32
# include "threads-win32.h"
if (!err) {
if (VIR_ALLOC(err) < 0)
return NULL;
- virThreadLocalSet(&virLastErr, err);
+ if (virThreadLocalSet(&virLastErr, err) < 0)
+ VIR_FREE(err);
}
return err;
}
virErrorFunc handler = virErrorHandler;
void *userData = virUserData;
- /* Should never happen, but doesn't hurt to check */
+ /* Can only happen on OOM. */
if (!err)
return;