Skip to content

Commit

Permalink
mx_mysql: mx_mysql_statement_close*: Allow NULL
Browse files Browse the repository at this point in the history
Allow mx_mysql_statement_close* functions to be called with a pointer to
a NULL value. This makes the daemon more robust when the functions are
used as cleanup functions, e.g.

    __attribute__((cleanup(mx_mysql_statement_close)))
    struct mx_mysql_stmt *stmt = mx_mysql_statement_prepare(mysql,"...");
    if (!stmt) {
        fprintf(stderr, "mx_mysql_stmt_prepare: %s\n", mx_mysql_error());
        return;
    }
  • Loading branch information
donald committed Jan 10, 2024
1 parent d4c2486 commit 3565e85
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions mx_mysql.c
Original file line number Diff line number Diff line change
Expand Up @@ -1154,8 +1154,8 @@ struct mx_mysql_stmt *mx_mysql_statement_prepare(struct mx_mysql *mysql, char *s

int mx_mysql_statement_close(struct mx_mysql_stmt **stmt)
{
assert(stmt);
assert(*stmt);
if (*stmt == NULL)
return 0;

mx__mysql_stmt_free_result(*stmt);
mx__mysql_stmt_close(*stmt);
Expand All @@ -1169,8 +1169,8 @@ int mx_mysql_statement_close(struct mx_mysql_stmt **stmt)

int mx_mysql_statement_close_no_bind_cleanup(struct mx_mysql_stmt **stmt)
{
assert(stmt);
assert(*stmt);
if (*stmt == NULL)
return 0;

mx__mysql_stmt_free_result(*stmt);
mx__mysql_stmt_close(*stmt);
Expand Down

0 comments on commit 3565e85

Please sign in to comment.