diff options
author | Christophe Genevey Metat <genevey.christophe@gmail.com> | 2016-06-09 15:39:57 +0000 |
---|---|---|
committer | Christophe Genevey Metat <genevey.christophe@gmail.com> | 2016-06-09 15:39:57 +0000 |
commit | 7c6eeca83081852d0eb323af94da3b2001357538 (patch) | |
tree | 7996e3f116025cb481b7ecd262b38769abc3c968 /src/my/my_result_helper.c | |
parent | a970e9d70979c0e378a009791dc9da6c029f8526 (diff) | |
download | gnunet-7c6eeca83081852d0eb323af94da3b2001357538.tar.gz gnunet-7c6eeca83081852d0eb323af94da3b2001357538.zip |
fix memory leak
Diffstat (limited to 'src/my/my_result_helper.c')
-rw-r--r-- | src/my/my_result_helper.c | 79 |
1 files changed, 15 insertions, 64 deletions
diff --git a/src/my/my_result_helper.c b/src/my/my_result_helper.c index 6f1b27065..9c04b9bed 100644 --- a/src/my/my_result_helper.c +++ b/src/my/my_result_helper.c | |||
@@ -74,14 +74,13 @@ post_extract_varsize_blob (void *cls, | |||
74 | 74 | ||
75 | if (rs->mysql_bind_output_length != size) | 75 | if (rs->mysql_bind_output_length != size) |
76 | return GNUNET_SYSERR; /* 'unsigned long' does not fit in size_t!? */ | 76 | return GNUNET_SYSERR; /* 'unsigned long' does not fit in size_t!? */ |
77 | |||
77 | buf = GNUNET_malloc (size); | 78 | buf = GNUNET_malloc (size); |
78 | 79 | ||
79 | results[0].buffer = buf; | 80 | results[0].buffer = buf; |
80 | results[0].buffer_length = size; | 81 | results[0].buffer_length = size; |
81 | results[0].buffer_type = MYSQL_TYPE_BLOB; | 82 | results[0].buffer_type = MYSQL_TYPE_BLOB; |
82 | 83 | ||
83 | fprintf(stderr, "size : %d\n", size); | ||
84 | |||
85 | if (0 != | 84 | if (0 != |
86 | mysql_stmt_fetch_column (stmt, | 85 | mysql_stmt_fetch_column (stmt, |
87 | results, | 86 | results, |
@@ -92,8 +91,6 @@ post_extract_varsize_blob (void *cls, | |||
92 | return GNUNET_SYSERR; | 91 | return GNUNET_SYSERR; |
93 | } | 92 | } |
94 | 93 | ||
95 | printf("buf : %s\n", (char*)buf); | ||
96 | |||
97 | *(void **) rs->dst = buf; | 94 | *(void **) rs->dst = buf; |
98 | *rs->result_size = size; | 95 | *rs->result_size = size; |
99 | 96 | ||
@@ -111,16 +108,14 @@ static void | |||
111 | cleanup_varsize_blob (void *cls, | 108 | cleanup_varsize_blob (void *cls, |
112 | struct GNUNET_MY_ResultSpec *rs) | 109 | struct GNUNET_MY_ResultSpec *rs) |
113 | { | 110 | { |
114 | void *ptr; | 111 | void **ptr = (void **)rs->dst; |
115 | |||
116 | ptr = * (void **) rs->dst; | ||
117 | if (NULL == ptr) | ||
118 | return; | ||
119 | GNUNET_free (ptr); | ||
120 | *(void **) rs->dst = NULL; | ||
121 | *rs->result_size = 0; | ||
122 | } | ||
123 | 112 | ||
113 | if (NULL != *ptr) | ||
114 | { | ||
115 | GNUNET_free (*ptr); | ||
116 | *ptr = NULL; | ||
117 | } | ||
118 | } | ||
124 | 119 | ||
125 | /** | 120 | /** |
126 | * Variable-size result expected | 121 | * Variable-size result expected |
@@ -219,6 +214,7 @@ GNUNET_MY_result_spec_fixed_size (void *ptr, | |||
219 | { | 214 | { |
220 | .pre_conv = &pre_extract_fixed_blob, | 215 | .pre_conv = &pre_extract_fixed_blob, |
221 | .post_conv = &post_extract_fixed_blob, | 216 | .post_conv = &post_extract_fixed_blob, |
217 | .cleaner = NULL, | ||
222 | .dst = (void *)(ptr), | 218 | .dst = (void *)(ptr), |
223 | .dst_size = ptr_size, | 219 | .dst_size = ptr_size, |
224 | .num_fields = 1 | 220 | .num_fields = 1 |
@@ -508,31 +504,8 @@ pre_extract_string (void * cls, | |||
508 | results[0].buffer = (char *)rs->dst; | 504 | results[0].buffer = (char *)rs->dst; |
509 | results[0].buffer_length = rs->dst_size; | 505 | results[0].buffer_length = rs->dst_size; |
510 | results[0].length = &rs->mysql_bind_output_length; | 506 | results[0].length = &rs->mysql_bind_output_length; |
511 | /* | 507 | |
512 | char **str = rs->dst; | 508 | return GNUNET_OK; |
513 | size_t len; | ||
514 | const char *res; | ||
515 | |||
516 | *str = NULL; | ||
517 | |||
518 | if (results->is_null) | ||
519 | { | ||
520 | return GNUNET_SYSERR; | ||
521 | } | ||
522 | |||
523 | len = results->buffer_length; | ||
524 | res = results->buffer; | ||
525 | |||
526 | *str = GNUNET_strndup (res, | ||
527 | len); | ||
528 | |||
529 | if (NULL == *str) | ||
530 | { | ||
531 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
532 | "Results contains bogus value (fail to decode)\n"); | ||
533 | return GNUNET_SYSERR; | ||
534 | } | ||
535 | */ return GNUNET_OK; | ||
536 | } | 509 | } |
537 | 510 | ||
538 | 511 | ||
@@ -559,32 +532,6 @@ post_extract_string (void * cls, | |||
559 | if (rs->dst_size != rs->mysql_bind_output_length) | 532 | if (rs->dst_size != rs->mysql_bind_output_length) |
560 | return GNUNET_SYSERR; | 533 | return GNUNET_SYSERR; |
561 | return GNUNET_OK; | 534 | return GNUNET_OK; |
562 | /* | ||
563 | char **str = rs->dst; | ||
564 | size_t len; | ||
565 | const char *res; | ||
566 | |||
567 | *str = NULL; | ||
568 | |||
569 | if (results->is_null) | ||
570 | { | ||
571 | return GNUNET_SYSERR; | ||
572 | } | ||
573 | |||
574 | len = results->buffer_length; | ||
575 | res = results->buffer; | ||
576 | |||
577 | *str = GNUNET_strndup (res, | ||
578 | len); | ||
579 | |||
580 | if (NULL == *str) | ||
581 | { | ||
582 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
583 | "Results contains bogus value (fail to decode)\n"); | ||
584 | return GNUNET_SYSERR; | ||
585 | } | ||
586 | return GNUNET_OK; | ||
587 | */ | ||
588 | } | 535 | } |
589 | 536 | ||
590 | 537 | ||
@@ -600,6 +547,7 @@ GNUNET_MY_result_spec_string (char **dst) | |||
600 | struct GNUNET_MY_ResultSpec res = { | 547 | struct GNUNET_MY_ResultSpec res = { |
601 | .pre_conv = &pre_extract_string, | 548 | .pre_conv = &pre_extract_string, |
602 | .post_conv = &post_extract_string, | 549 | .post_conv = &post_extract_string, |
550 | .cleaner = NULL, | ||
603 | .dst = (void *) dst, | 551 | .dst = (void *) dst, |
604 | .dst_size = 0, | 552 | .dst_size = 0, |
605 | .num_fields = 1 | 553 | .num_fields = 1 |
@@ -704,6 +652,7 @@ GNUNET_MY_result_spec_uint16 (uint16_t *u16) | |||
704 | struct GNUNET_MY_ResultSpec res = { | 652 | struct GNUNET_MY_ResultSpec res = { |
705 | .pre_conv = &pre_extract_uint16, | 653 | .pre_conv = &pre_extract_uint16, |
706 | .post_conv = &post_extract_uint16, | 654 | .post_conv = &post_extract_uint16, |
655 | .cleaner = NULL, | ||
707 | .dst = (void *) u16, | 656 | .dst = (void *) u16, |
708 | .dst_size = sizeof (*u16), | 657 | .dst_size = sizeof (*u16), |
709 | .num_fields = 1 | 658 | .num_fields = 1 |
@@ -778,6 +727,7 @@ GNUNET_MY_result_spec_uint32 (uint32_t *u32) | |||
778 | struct GNUNET_MY_ResultSpec res = { | 727 | struct GNUNET_MY_ResultSpec res = { |
779 | .pre_conv = &pre_extract_uint32, | 728 | .pre_conv = &pre_extract_uint32, |
780 | .post_conv = &post_extract_uint32, | 729 | .post_conv = &post_extract_uint32, |
730 | .cleaner = NULL, | ||
781 | .dst = (void *) u32, | 731 | .dst = (void *) u32, |
782 | .dst_size = sizeof (*u32), | 732 | .dst_size = sizeof (*u32), |
783 | .num_fields = 1 | 733 | .num_fields = 1 |
@@ -854,6 +804,7 @@ GNUNET_MY_result_spec_uint64 (uint64_t *u64) | |||
854 | struct GNUNET_MY_ResultSpec res = { | 804 | struct GNUNET_MY_ResultSpec res = { |
855 | .pre_conv = &pre_extract_uint64, | 805 | .pre_conv = &pre_extract_uint64, |
856 | .post_conv = &post_extract_uint64, | 806 | .post_conv = &post_extract_uint64, |
807 | .cleaner = NULL, | ||
857 | .dst = (void *) u64, | 808 | .dst = (void *) u64, |
858 | .dst_size = sizeof (*u64), | 809 | .dst_size = sizeof (*u64), |
859 | .num_fields = 1 | 810 | .num_fields = 1 |