Does libxml2 (C API) provide a way to remove a registered set of xmlOutputCallbacks, without removing ALL registered output callbacks? - c

I am working on a custom I/O layer for libxml2 and have come across an oddity in the de-registration of Output callbacks. There appears to be no way to remove just one set of output callbacks. Am I missing something? I can provide a working example if the following pseudo-code does not clarify the question.
static int _in_matcher(const char* URI) {...}
static void* _in_opener(const char* URI) {...}
static int _in_reader(void *ctxt, char *in_buf, int buf_len) {...}
static int _in_closer(void *ctxt) {...}
int test_input_callbacks(const char *file_name)
{
int handler = xmlRegisterInputCallbacks(
_in_matcher,
_in_opener,
_in_reader,
_in_closer,
);
...
xmlDocPtr doc = xmlParseFile(file_name);
xmlFree(doc);
...
xmlPopInputCallbacks();
}
static int _out_matcher( const char *URI) {...}
static void* _out_opener( const char *URI) {...}
static int _out_writer( void *ctxt, const char *out_buf, int buf_len) {...}
static int _outcloser( void *ctxt) {...}
int test_output_callbacks(const char *file_name)
{
int handler = xmlRegisterOutputCallbacks(
_out_matcher,
_out_opener,
_out_writer,
_out_closer,
);
...
int result = xmlSaveFormatFileEnc(URI, doc, NULL, 0);
xmlFree(doc);
...
/* There does not appear to be a function that
* removes _only_ the last output callbacks
* registered!
*/
==> ?? xmlPopOutputCallbacks() ?? <==
}
As a work around, I added this function to my [local] version of libxml2 (2-2.9.10):
int
xmlPopOutputCallbacks(void)
{
if (!xmlOutputCallbackInitialized)
return(-1);
if (xmlOutputCallbackNr <= 0)
return(-1);
xmlOutputCallbackNr--;
xmlOutputCallbackTable[xmlOutputCallbackNr].matchcallback = NULL;
xmlOutputCallbackTable[xmlOutputCallbackNr].opencallback = NULL;
xmlOutputCallbackTable[xmlOutputCallbackNr].writecallback = NULL;
xmlOutputCallbackTable[xmlOutputCallbackNr].closecallback = NULL;
return(xmlOutputCallbackNr);
}
It works, but I get the nagging feeling there is either something I am missing; or there is a valid reason why libxml2 does not provide the ability to remove individual sets of output callbacks.
Any help/advice would be greatly appreciated!
Thanks,
Tom

Related

Correct way to pass a char array to a callback function in C

I'm dynamically repeatedly creating a char[] of fixed length 32 and pass it to function that stores the pointer in a struct and passes it later on to a callback function.
Unforntunately I don't know the correct way to allocate the memory for this string data.
This is the function, where the nonceHex is created in a loop
static int polling_thread(struct pt *pt, uint16_t ticks)
{
static uint16_t timer;
timer += ticks;
PT_BEGIN(pt);
while (1)
{
uint8_t nonce[NONCE_LEN] = {};
char nonceHex[2 * NONCE_LEN] = "";
RNG(nonce, NONCE_LEN);
hex_encode(nonce, sizeof(nonce), nonceHex);
...
struct mg_connection *c = mg_connect_http(mgos_get_mgr(), http_cb, nonceHex, url, (const char *)sEtagHeader, NULL);
...
timer = 0;
PT_WAIT_UNTIL(pt, timer >= 500);
}
PT_END(pt);
}
And this is the callback function where the char[] is passed by the framework (mongoose os) as cb_arg
static void http_cb(struct mg_connection *nc, int ev, void *evd, void *cb_arg)
{
...
case MG_EV_HTTP_REPLY:
{
const char *nonceHex = (const char *)cb_arg;
LOG(LL_DEBUG, ("http_cb nonce: %s", nonceHex));
LOG(LL_DEBUG, ("http_cb nc->user_data: %s", (const char *)nc->user_data));
}
...
}
Unfortunately when I run this code I don't received the nonceHex but something that looks like unitialized char[]
http_cb nonce: Pa�?`B�?�a�?���?�c�?
http_cb nc->user_data: Pa�?`B�?�a�?���?�c�?
Do I need to dynamically malloc the char[]? If I use a static char[] it works, but it's not correct as nonceHex is overwritten by subsequent loop cycles and so cb_arg in the callback function contains invalid data.
Can anyone tell me how this would be programmed correctly?
#######################################################
Changed my function to
static int polling_thread(struct pt *pt, uint16_t ticks)
{
static uint16_t timer;
timer += ticks;
PT_BEGIN(pt);
while (1)
{
...
uint8_t nonce[NONCE_LEN] = {};
char *nonceHex = malloc(2 * NONCE_LEN + 1);
RNG(nonce, NONCE_LEN);
hex_encode(nonce, sizeof(nonce), nonceHex);
*(nonceHex+2 * NONCE_LEN) = '\0';
struct mg_connection *c = mg_connect_http(mgos_get_mgr(), http_cb, nonceHex, url, (const char *)sEtagHeader, NULL);
...
timer = 0;
PT_WAIT_UNTIL(pt, timer >= 500);
}
PT_END(pt);
}
Added call to free in callback function
static void http_cb(struct mg_connection *nc, int ev, void *evd, void *cb_arg)
{
...
case MG_EV_HTTP_REPLY:
{
char *nonceHex = (char *)cb_arg;
LOG(LL_DEBUG, ("http_cb nonce: %s", nonceHex));
LOG(LL_DEBUG, ("http_cb nc->user_data: %s", (const char *)nc->user_data));
free(nonceHex);
}
...
}
This results in a panic
Guru Meditation Error: Core 1 panic'ed (LoadProhibited). Exception was unhandled.
Can you see my fault?

Lib using Tcl C API is crashing maybe due bad refCount usage

I'm a beginner at Tcl C API and I'm trying to understand how to use it. I have this code that gets a tcl list from get_my_list proc and then I iterate over it to dispatch some info, in this case, info related to attributes A, B and C that I get with get_attr_info proc. When I run it in a very simple example that basically has only this code, everything works perfectly, but when I add this lib in a big tcl project, eventually it crashes. I suspect that it's due to bad usage of reference counting of tcl objects, I mean, their lifetimes. What could I be doing wrong in the example below? I'm using Tcl 8.6.
Tcl_Obj* Get_Info(Tcl_Interp *interp, const char* info, const char* attr) {
char cmd[256];
sprintf(cmd, "get_attr_info %s %s", info, attr);
Tcl_Eval(interp, cmd);
return Tcl_GetObjResult(interp);
}
static int Copy_Info(ClientData cdata, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[]) {
Tcl_Eval(interp, "get_my_list");
Tcl_Obj *const my_list = Tcl_GetObjResult(interp);
int my_list_size;
Tcl_ListObjLength(interp, my_list, &my_list_size);
Tcl_IncrRefCount(my_list);
for (int i = 0; i < my_list_size; ++i) {
Tcl_Obj* current_info_obj;
Tcl_ListObjIndex(interp, my_list, i, &current_info_obj);
const char* current_info_ctr = Tcl_GetStringFromObj(current_info_obj, NULL);
/* getting info A */
Tcl_Obj* info_a_obj = Get_Info(current_info_ctr, "A");
const char* info_a = Tcl_GetStringFromObj(info_a_obj, NULL);
Copy_Info_A(info_a);
/* getting info B */
Tcl_Obj* info_b_obj = Get_Info(current_info_ctr, "B");
const char* info_b = Tcl_GetStringFromObj(info_b_obj, NULL);
Copy_Info_B(info_b);
/* getting info C */
Tcl_Obj* info_c_obj = Get_Info(current_info_ctr, "C");
const char* info_c = Tcl_GetStringFromObj(info_c_obj, NULL);
Copy_Info_C(info_c);
}
Tcl_DecrRefCount(my_list);
Tcl_FreeResult(interp);
return TCL_OK;
}
The tricky bit is that you call Tcl_Eval() inside Get_Info(), which can do all sorts of things with reference count management of values that you're not holding your own reference to, including shimmering away the list representation of the value you're holding a reference to in my_list, which can pull the rug out from under its elements. In particular, the object referred to in current_info_obj must have its reference count incremented from after the Tcl_ListObjIndex() to the end of the loop body.
// ...
for (int i = 0; i < my_list_size; ++i) {
Tcl_Obj* current_info_obj;
Tcl_ListObjIndex(interp, my_list, i, &current_info_obj);
// HOLD THE REFERENCE; IT OWNS THE current_info_ctr STRING FOR US
Tcl_IncrRefCount(current_info_obj);
const char* current_info_ctr = Tcl_GetStringFromObj(current_info_obj, NULL);
/* getting info A */
Tcl_Obj* info_a_obj = Get_Info(current_info_ctr, "A");
const char* info_a = Tcl_GetStringFromObj(info_a_obj, NULL);
Copy_Info_A(info_a);
/* getting info B */
Tcl_Obj* info_b_obj = Get_Info(current_info_ctr, "B");
const char* info_b = Tcl_GetStringFromObj(info_b_obj, NULL);
Copy_Info_B(info_b);
/* getting info C */
Tcl_Obj* info_c_obj = Get_Info(current_info_ctr, "C");
const char* info_c = Tcl_GetStringFromObj(info_c_obj, NULL);
Copy_Info_C(info_c);
// RELEASE THE REFERENCE
Tcl_DecrRefCount(current_info_obj);
}
// ...
Improving your code
You can also do a short-cut, and use Tcl_GetString(objPtr) in place of Tcl_GetStringFromObj(objPtr, NULL). You might put that inside Get_Info. You probably also ought to consider switching to using Tcl_EvalObjv(), as that's a faster API (it avoids a level of parsing), though a more complex one to use.
const char *Get_Info(Tcl_Interp *interp, Tcl_Obj* info, const char* attr) {
Tcl_Obj *argv[3], *result;
argv[0] = Tcl_NewStringObj("get_attr_info", -1); // cacheable
argv[1] = info;
argv[2] = Tcl_NewStringObj(attr, -1);
Tcl_IncrRefCount(argv[0]);
Tcl_IncrRefCount(argv[1]);
Tcl_IncrRefCount(argv[2]);
// It's very bad form to omit error handling
if (Tcl_EvalObjv(interp, 3, argv, 0) != TCL_OK) {
Tcl_Panic("problem: %s", Tcl_GetString(Tcl_GetObjResult(interp)));
}
result = Tcl_GetObjResult(interp);
Tcl_DecrRefCount(argv[0]);
Tcl_DecrRefCount(argv[1]);
Tcl_DecrRefCount(argv[2]);
return Tcl_GetString(result);
}
There are cases where it's possible to reduce the amount of reference count handling. Don't worry about doing that to start with! Better to definitely avoid crashes!
Tcl_EvalObjv is (effectively) what Tcl_Eval calls to actually dispatch a command after parsing in interactive mode, and it's what the bytecode engine calls to evaluate any non-inlined command. It's much more efficient than parsing a string into words.

How to check if a file exists in a given path in C?

I am trying to find the file(say marks.txt) in the particular path passed as argument to a function. Is it possible to give the filename and path as arguments to a function which checks if the file exists and prints out the path?
The below function only takes path as argument.
int fileexists(const char *path){
File *ptr = fopen(path, "r");
if (fptr == NULL)
return 0;
fclose(fptr);
return 1;
}
The required function prototype :
int fileexists(const char *path, const char *filename)
There are two parts to this question, and the right answers to them depend on what you're trying to do.
Concatenate a directory name and a file name to form a full path name.
Determine whether a file (referred to by a full path name) exists or not.
Concatenating a directory name and a file name is straightforward. Your friendsstrcpy and strcat will do most of the work. There are a few minor details to be careful of: (a) You'll need a big enough buffer for the full pathname, and you'll need to decide whether to use a fixed-size array (perhaps of size MAX_PATH), or a malloc'ed buffer; (b) you might need to insert an explicit '/' character (and it usually doesn't hurt to stick one in even if the directory string already ends in one); (c) under Windows you might want to use '\\' instead of '/'.
And then determining whether a file named by a full pathname exists is already well answered over at What's the best way to check if a file exists in C?. The big question to ask here is, are you asking whether the file exists in preparation to doing something with the file? If so, you have a serious vulnerability if you check for the file's existence, but then before you do the other thing, something else happens to cause the file to appear or disappear. So rather than checking-and-then-doing, it's usually better to just try doing the other thing, and deal gracefully with any errors.
The function you have checks if the file can be opened, but it will fail for some files that exist but you have no rights to open. I'd use stat instead. To concatenate the path and filename you can use string functions.
The usual Unix C APIs are dismal. It takes lots of effort to do the simplest of things correctly - and even then I'm not sure that I didn't forget some Unix-ism like signal handling or some obscure error cases. I.e. stuff that's rather trivial to get right in modern C++.
I wish someone designed a modern C system API and implemented it for at least Linux, so that our suffering would end...
Usually, string concatenation requires some higher level API to be done while maintaining a modicum of sanity. Thus, the example below uses a strbuilder class to build the string. This makes things vaguely readable and avoids most common mistakes.
#include <assert.h>
#include <errno.h>
#include <limits.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
struct strbuilder {
unsigned items, item;
size_t length, *lengths;
char *str, *dst;
};
bool strbuilder_pass(struct strbuilder *builder, int *rc);
void strcat_str(struct strbuilder *builder, const char *src);
void strcat_c_ifnone(struct strbuilder *builder, char c);
bool strbuilder_is_freed(const struct strbuilder *builder);
int fileExists(const char *path, const char *filename)
{
const char pathSep = '/';
int rc;
struct strbuilder bld = {0};
while (strbuilder_pass(&bld, &rc))
{
strcat_str(&bld, path);
strcat_c_ifnone(&bld, pathSep);
strcat_str(&bld, filename);
if (!rc)
{
struct stat statbuf;
printf("path = %s\n", bld.str);
rc = stat(bld.str, &statbuf);
}
}
assert(strbuilder_is_freed(&bld));
return rc;
}
int main()
{
int rc = fileExists("/", "dev");
assert(rc == 0);
return 0;
}
The string building is controlled by a strbuilder_pass function, which advances the string builder's state through five passes of operation:
Determine the number of items whose width has to be stored (avoids the need to call strlen twice).
Prepare the length storage vector. Determine the length of the buffer needed.
Prepare the output string buffer. Concatenate the elements into the buffer.
Use the output string buffer.
Free the output string buffer.
This API is not particularly special, but fits this use case. Some other ad-hoc approach would work too, but this is IMHO a bit more elegant.
void strbuilder_free(struct strbuilder *builder)
{
free(builder->lengths);
free(builder->str);
memset(builder, 0, sizeof(*builder));
}
bool strbuilder_pass(struct strbuilder *builder, int *rc)
{
if (!builder->length) {// start of pass 1
builder->length = 1; /*term*/
*rc = EAGAIN;
return true;
}
else if (!builder->lengths) // end of pass 1
{
builder->lengths = malloc(sizeof(*builder->lengths) * builder->items);
if (builder->lengths)
return true;
*rc = ENOMEM;
}
else if (!builder->str) // end of pass 2
{
builder->dst = (builder->str = malloc(builder->length));
builder->item = 0;
builder->length = 0;
if (builder->dst) {
*builder->dst = '\0';
return true;
}
*rc = ENOMEM;
}
else if (builder->dst) // end of pass 3
{
while (*builder->dst) { // include optional content
builder->dst++; // skip
builder->length++;
}
builder->dst = NULL;
*rc = 0;
return true;
}
else if (!builder->dst) // end of pass 4 (if any)
{}
else {
*rc = EINVAL;
}
strbuilder_free(builder);
return false;
}
void strcat_str(struct strbuilder *builder, const char *src)
{
if (!src)
return;
if (!builder->lengths) // pass 1
builder->items ++;
else if (!builder->str) // pass 2
{
size_t len = strlen(src);
builder->lengths[builder->item++] = len;
builder->length += len;
}
else if (builder->dst) // pass 3
{
size_t len = builder->lengths[builder->item++];
if (*builder->dst && (!len || *builder->dst != *src))
{
builder->dst++;
builder->length++;
}
memcpy(builder->dst, src, len);
builder->dst += len;
builder->length += len;
*builder->dst = '\0';
}
}
void strcat_c_ifnone(struct strbuilder *builder, char c)
{
if (!builder->lengths) {} // pass 1
else if (!builder->str) // pass 2
{
if (c) builder->length ++;
}
else if (builder->dst) // pass 3
{
if (!builder->length || builder->dst[-1] != c)
*(builder->dst) = c;
}
}
bool strbuilder_is_freed(const struct strbuilder *builder)
{
return !builder || (!builder->lengths && !builder->str);
}
You probably want something like this (no error checking for brevity):
...
#include <string.h> // for str* functions
#include <unistd.h> // for access
#include <stdlib.h> // for malloc
...
int fileexists(const char *path, const char *filename)
{
char *name= malloc(strlen(path) + strlen(filename) + 1);
strcpy(name, path);
strcat(name, filename);
int retval = access(name, F_OK) == 0;
free(name);
return retval;
}
Call like this:
if (fileexists("/some/path/", "somefilename.txt")) ...

Freeing memory gives segmentation fault [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 4 years ago.
Improve this question
I've been trying to work with structures, pointers and memory in C.
I have created this structure
typedef struct {
int id;
char *name;
} Object;
here is constructor
void object_ctor(Object *o, int id, char *name)
{
o->id = id;
o->name = malloc(sizeof(name));
if(sizeof(o->name)!=sizeof(name))
{
o->name=NULL;
}
else
{
strcpy(o->name, name);
}
}
here is decleration of o1
char tmp_name[] = "Hello 1";
Object o1;
object_ctor(&o1, 1, tmp_name);
here is destructor
void object_dtor(Object *o)
{
if(o->name != NULL)
{
free(o->name);
o->name = NULL;
}
}
printing object
void print_object(Object *o)
{
printf("ID: %d, NAME: %s\n", o->id, o->name);
}
calling copy
Object copy;
print_object(object_cpy(&copy, &o1));
and I´m trying create a copy of one structure to another (I have already constructed them).
Object *object_cpy(Object *dst, Object *src)
{
if(src!=NULL)
{
const size_t len_str=strlen(src->name)+1;
dst->name = malloc(10000000);
dst->id = src->id;
strncpy (dst->name, src->name,len_str);
}
if (strcmp(dst->name,src->name)!=0)
{
dst->name = NULL;
}
return dst;
}
But then when I'm trying to free both copy and original src I get a segmentation fault. I've been trying to run it through gdb and it said that I'm freeing same memory twice so I assume that the code for copying is wrong, but I don't know where.
And here is code that gives me segmentation fault
printf("\nCOPY EMPTY\n");
object_dtor(&copy);
o1.id = -1;
free(o1.name);
o1.name = NULL;
object_cpy(&copy, &o1);
print_object(&copy);
print_object(&o1);
I´m including these libraries
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
I'm using the std=c99 flag for to compile.
There is at least a problem here:
void object_ctor(Object *o, int id, char *name)
{
o->id = id;
o->name = malloc(sizeof(name));
if (sizeof(o->name) != sizeof(name))
{
o->name = NULL;
}
else
{
strcpy(o->name, name);
}
}
sizeof(name) is not the length of the string pointed by name. You need strlen(name) + 1 (+1 for the NUL terminator).
And your test if (sizeof(o->name) != sizeof(name)) is pointless, and I'm not sure what you're trying to achieve here.
You probably want this:
void object_ctor(Object *o, int id, char *name)
{
o->id = id;
o->name = malloc(strlen(name) + 1);
if (o->name != NULL)
strcpy(o->name, name);
}
There are similar problems in object_cpy:
pointless use of strncpy
pointless allocation of a 10Mb buffer
pointless test strcmp(dst->name, src->name)
You probably want this:
Object *object_cpy(Object *dst, Object *src)
{
if (src != NULL)
{
const size_t len_str = strlen(src->name) + 1;
dst->name = malloc(len_str);
if (dst->name != NULL)
{
dst->id = src->id;
strcpy(dst->name, src->name);
}
}
return dst;
}
With these corrections following code works fine:
int main()
{
char tmp_name[] = "Hello 1";
Object o1, copy;
object_ctor(&o1, 1, tmp_name);
object_cpy(&copy, &o1);
print_object(&copy);
print_object(&o1);
object_dtor(&o1);
object_dtor(&copy);
}
Event if this is not directly an answer to your problem, I'll give you how I organize my code in order to avoid memory problem like yours.
First, it all resolve around a structure.
To each structure, if needed, I do a "Constructor" and a "Destructor".
The purpose of the constructor is simply to set the structure in a coherent state. It can't never fail (implying that any code that could fail, like malloc, should not be in the constructor).
The purpose of the destructor is to clean the structure.
One little trick that I like to use is to put the constructor in a macro, allowing me to do something like 'Object var = OBJET_CONSTRUCTOR'.
Of course, it's not alway possible, it's up to you to be carreful.
For your code, it could be :
typedef struct {
int id;
char *name;
} Object;
#define OBJECT_CONSTRUCTOR {.id = -1,\ \\ Assuming -1 is relevant in your case, like an error code or a bad id value. Otherwise, it's useless.
.name = NULL}
void Object_Constructor(Object *self)
{
Object clean = OBJECT_CONSTRUCTOR;
*self = clean;
}
void Object_Destructor(Object *self)
{
free(self->name);
}
Here we go.
How to use it is simple : You always begin by the constructor, and you alway end by the destructor. That's why it's useless to set the char pointer "name" to NULL in the destructor, because it should not be used after by any other function that the constructor.
Now, you can have "initialisation" function. You can do a plain initialisation (it is your constructor function), or a copy initialisation, etc etc
Just keep in mind that the structure have been called into the constructor. If not, it's the developer fault and you do not have to take that in count.
A behavior that can be nice is, in case of error, to not modify the structure.
Either the structure is entierly modified in succes, or not at all.
For complex structure that can fail at many point, you can do that by "swapping" the result at the end.
void Object_Swap(Object *first, Object *second)
{
Object tmp = OBJECT_CONSTRUCTOR;
tmp = *fisrt;
*first = *second;
*second = tmp;
}
bool Object_InitByPlainList(Object *self, int id, consr char *name)
{
Object newly = OBJECT_CONSTRUCTOR;
bool returnFunction = false;
newly.id = id;
if (!(newly.name = strdup(name))) {
printf("error : %s : strdup(name) : name='%s', errno='%s'.\n", __func__, name, strerror(errno));
goto END_FUNCTION;
}
// Success !
Object_Swap(self, &newly);
returnFunction = true;
/* GOTO */END_FUNCTION:
Object_Destructor(&newly);
return (returnFunction);
}
It may be seem overcomplicated at the first glance, but that organization allow you to add more futur step "that can fail" cleanly.
Now, you can even do something this simply :
bool Object_InitByCopy(Object *dst, Object *src)
{
return (Object_InitByPlainList(dst, src->id, src->name));
}
All you have to do is to say in the documentation :
The first function to be called have to be "Object_Constructor"
After the "Object_Constructor", only the "Object_Init*" function can be called.
The last function to be call have to be "Object_Destructor"
That's all. You can add any "Object_*" function that you whant, like :
void Object_Print(const Object *self)
{
printf("ID: %d, NAME: %s\n", self->id, self->name);
}
Hope this organization will solve your memory problem.
An example :
int main(void)
{
Object test = OBJECT_CONSTRUCTOR;
Object copy = OBJECT_CONSTRUCTOR;
if (!Object_InitByPlainList(&test, 1, "Hello World !")) {
// The function itself has logged why it has fail, so no need to add error printf here
return (1);
}
Object_Print(&test);
if (!Object_Copy(&copy, &test)) {
return (1);
}
Object_Destructor(&test);
Object_Destructor(&copy);
return (0);
}

What does the usage of `(void)struct_pointer`?

I am now reading a project and find some of the codes hard to understand, like below:
struct mcachefs_metadata_t* mdata_root;
...
mcachefs_metadata_release(mdata_root);
And the definition of mcachefs_metadata_release is as below:
void
mcachefs_metadata_release(struct mcachefs_metadata_t* mdata)
{
(void) mdata;
mcachefs_metadata_unlock ();
}
And the definitioin of mcachefs_metadata_unlock is as below:
#define mcachefs_metadata_unlock() mcachefs_mutex_unlock ( &mcachefs_metadata_mutex, "metadata", __CONTEXT );
Then, the mcachefs_mutex_unlock function:
void
mcachefs_mutex_unlock(struct mcachefs_mutex_t* mutex, const char* name,
const char* context)
{
int res;
...
mutex->owner = 0;
mutex->context = NULL;
res = pthread_mutex_unlock(&(mutex->mutex));
if (res == 0)
{
return;
}
...
}
I could not understand what does the (void) mdata; mean in the
mcachefs_metadata_release function. What does the usage of it?
It's for suppressing unused argument: mdata compiler warnings. Rather bad practice, by the way.

Resources