From 073e944c91254860904050e8b36813ffe0d3c59c Mon Sep 17 00:00:00 2001
From: Julien Schueller <schueller@phimeca.com>
Date: Mon, 4 Jul 2022 13:23:06 +0200
Subject: [PATCH] options: nlopt_set_xtol_abs check xtol_abs

Closes #461
---
 src/api/options.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/src/api/options.c b/src/api/options.c
index 853a5d67..e2c59e8d 100644
--- a/src/api/options.c
+++ b/src/api/options.c
@@ -691,6 +691,12 @@ GETSET(ftol_rel, double, ftol_rel) GETSET(ftol_abs, double, ftol_abs) GETSET(xto
 {
     if (opt) {
         nlopt_unset_errmsg(opt);
+	if (!xtol_abs)
+	{
+	    free(opt->xtol_abs);
+	    opt->xtol_abs = NULL;
+	    return NLOPT_SUCCESS;
+	}
         if (!opt->xtol_abs && opt->n > 0) {
             opt->xtol_abs = (double *) calloc(opt->n, sizeof(double));
             if (!opt->xtol_abs) return NLOPT_OUT_OF_MEMORY;
@@ -738,6 +744,12 @@ nlopt_result NLOPT_STDCALL nlopt_set_x_weights(nlopt_opt opt, const double *x_we
     if (opt) {
         unsigned i;
         nlopt_unset_errmsg(opt);
+	if (!x_weights)
+	{
+	  free(opt->x_weights);
+	  opt->x_weights = NULL;
+	  return NLOPT_SUCCESS;
+	}
         for (i = 0; i < opt->n; i++)
             if (x_weights[i] < 0)
                 return ERR(NLOPT_INVALID_ARGS, opt, "invalid negative weight");