mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
saving: fix resource leak found by coverity
fp_get_data() returns a copy of a string that must be freed. Fix this in save-git.c. The analogous function in save-xml.c has already been fixed. However, change the code to be more idiomatic: since we own the pointer, make it "char *" instead of "const char *". Then we don't have to cast on free(). Ultimately, we really should change string manipulation code to C++. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
parent
91e4fb4769
commit
429230ced1
2 changed files with 5 additions and 3 deletions
|
@ -871,12 +871,14 @@ static void save_one_device(struct membuffer *b, const struct device *d)
|
|||
|
||||
static void save_one_fingerprint(struct membuffer *b, unsigned int i)
|
||||
{
|
||||
char *fp_data = fp_get_data(&fingerprint_table, i);
|
||||
put_format(b, "fingerprint model=%08x serial=%08x deviceid=%08x diveid=%08x data=\"%s\"\n",
|
||||
fp_get_model(&fingerprint_table, i),
|
||||
fp_get_serial(&fingerprint_table, i),
|
||||
fp_get_deviceid(&fingerprint_table, i),
|
||||
fp_get_diveid(&fingerprint_table, i),
|
||||
fp_get_data(&fingerprint_table, i));
|
||||
fp_data);
|
||||
free(fp_data);
|
||||
}
|
||||
|
||||
static void save_settings(git_repository *repo, struct dir *tree)
|
||||
|
|
|
@ -609,14 +609,14 @@ static void save_one_device(struct membuffer *b, const struct device *d)
|
|||
|
||||
static void save_one_fingerprint(struct membuffer *b, int i)
|
||||
{
|
||||
const char *data = fp_get_data(&fingerprint_table, i);
|
||||
char *data = fp_get_data(&fingerprint_table, i);
|
||||
put_format(b, "<fingerprint model='%08x' serial='%08x' deviceid='%08x' diveid='%08x' data='%s'/>\n",
|
||||
fp_get_model(&fingerprint_table, i),
|
||||
fp_get_serial(&fingerprint_table, i),
|
||||
fp_get_deviceid(&fingerprint_table, i),
|
||||
fp_get_diveid(&fingerprint_table, i),
|
||||
data);
|
||||
free((void *)data);
|
||||
free(data);
|
||||
}
|
||||
|
||||
int save_dives(const char *filename)
|
||||
|
|
Loading…
Add table
Reference in a new issue