summaryrefslogtreecommitdiffstats
path: root/cqrlogo.c
diff options
context:
space:
mode:
authorGravatar Christian Hesse <mail@eworm.de>2013-09-18 12:23:33 +0200
committerGravatar Christian Hesse <mail@eworm.de>2013-09-18 12:23:33 +0200
commitdd4a6120ed0a77691ea6f0f2d6262dcda05ce939 (patch)
tree42ec33293b78d4f5812500b83c0d3dd69f15c332 /cqrlogo.c
parentbb7d613e51922da93621268a05749e1183d77f92 (diff)
downloadcqrlogo-dd4a6120ed0a77691ea6f0f2d6262dcda05ce939.tar.gz
cqrlogo-dd4a6120ed0a77691ea6f0f2d6262dcda05ce939.tar.zst
fix same memory management errors found with valgrind
Diffstat (limited to 'cqrlogo.c')
-rw-r--r--cqrlogo.c16
1 files changed, 11 insertions, 5 deletions
diff --git a/cqrlogo.c b/cqrlogo.c
index a72fd2b..a44d661 100644
--- a/cqrlogo.c
+++ b/cqrlogo.c
@@ -90,7 +90,7 @@ int generate_png (struct bitmap_t *bitmap, const char *uri) {
# endif
png_set_text(png_ptr, info_ptr, pngtext, textcount);
- free(pngtext);
+ png_free (png_ptr, pngtext);
# if PNG_ENABLE_TEXT_VERSIONS
free(libsstr);
# endif
@@ -118,6 +118,9 @@ int generate_png (struct bitmap_t *bitmap, const char *uri) {
for (y = 0; y < bitmap->height; ++y)
png_free (png_ptr, row_pointers[y]);
png_free (png_ptr, row_pointers);
+ png_destroy_write_struct(&png_ptr, &info_ptr);
+
+ fclose(stdout);
return 0;
}
@@ -198,15 +201,18 @@ struct bitmap_t * encode_qrcode (const char *text, unsigned int scale, unsigned
/*** get_value ***/
int get_value(const char *query_string, const char *pattern, unsigned int *value, unsigned int def, unsigned int min, unsigned int max) {
char *match = NULL, *newpattern = NULL;
+ unsigned int length;
newpattern = strdup(pattern);
- newpattern = realloc(newpattern, strlen(newpattern) + 2);
- sprintf(newpattern + strlen(newpattern), "=");
+ length = strlen(newpattern);
+ /* length is without null termination, allocacte 4 bytes so we
+ * have "=", "%u" and null termination */
+ newpattern = realloc(newpattern, length + 4);
+ sprintf(newpattern + length, "=");
if ((match = strstr(query_string, newpattern)) != NULL) {
- newpattern = realloc(newpattern, strlen(newpattern) + 3);
- sprintf(newpattern + strlen(newpattern), "%%u");
+ sprintf(newpattern + length, "%%u");
if ((sscanf(match, newpattern, value)) > 0)
if (*value < min || *value > max)