static int gdb_generate_target_description(struct target *target, char **tdesc_out)
{
int retval = ERROR_OK;
- struct reg **reg_list;
+ struct reg **reg_list = NULL;
int reg_list_size;
+ char **features = NULL;
+ int feature_list_size = 0;
char *tdesc = NULL;
int pos = 0;
int size = 0;
if (retval != ERROR_OK) {
LOG_ERROR("get register list failed");
- return ERROR_FAIL;
+ retval = ERROR_FAIL;
+ goto error;
}
if (reg_list_size <= 0) {
- free(reg_list);
- return ERROR_FAIL;
+ LOG_ERROR("get register list failed");
+ retval = ERROR_FAIL;
+ goto error;
}
- char **features = NULL;
/* Get a list of available target registers features */
- retval = get_reg_features_list(target, &features, NULL, reg_list, reg_list_size);
+ retval = get_reg_features_list(target, &features, &feature_list_size, reg_list, reg_list_size);
if (retval != ERROR_OK) {
LOG_ERROR("Can't get the registers feature list");
- free(reg_list);
- return ERROR_FAIL;
+ retval = ERROR_FAIL;
+ goto error;
}
/* If we found some features associated with registers, create sections */
xml_printf(&retval, &tdesc, &pos, &size,
"</target>\n");
- free(reg_list);
+error:
+
+ /* note: features[] contains (feature_list_size + 1) elements */
+ for (int j = feature_list_size; j >= 0; j--)
+ free(features[j]);
free(features);
+ free(reg_list);
if (retval == ERROR_OK)
*tdesc_out = tdesc;
int retval = ERROR_OK;
struct reg **reg_list = NULL;
int reg_list_size = 0;
+ char **features = NULL;
int feature_list_size = 0;
char **features = NULL;
}
if (reg_list_size <= 0) {
+ LOG_ERROR("get register list failed");
retval = ERROR_FAIL;
goto error;
}
}
error:
- if (reg_list != NULL)
- free(reg_list);
- if (features != NULL)
- free(features);
+ /* note: features[] contains (feature_list_size + 1) elements */
+ for (int j = feature_list_size; j >= 0; j--)
+ free(features[j]);
+ free(features);
+
+ free(reg_list);
return retval;
}