Просмотр исходного кода

Fixed possible memory leak

tags/v0.5
Brice Figureau 17 лет назад
Родитель
Сommit
33a331dea8
1 измененных файлов: 20 добавлений и 4 удалений
  1. 20
    4
      ngx_http_uploadprogress_module.c

+ 20
- 4
ngx_http_uploadprogress_module.c Просмотреть файл

153
         if (header[i].key.len == x_progress_id.len
153
         if (header[i].key.len == x_progress_id.len
154
             && ngx_strncasecmp(header[i].key.data, x_progress_id.data,
154
             && ngx_strncasecmp(header[i].key.data, x_progress_id.data,
155
                            header[i].key.len) == 0) {
155
                            header[i].key.len) == 0) {
156
-            ret = ngx_pcalloc(r->pool, sizeof(ngx_str_t));
156
+            ret = ngx_calloc(r->pool, sizeof(ngx_str_t));
157
             ret->data = header[i].value.data;
157
             ret->data = header[i].value.data;
158
             ret->len = header[i].value.len;
158
             ret->len = header[i].value.len;
159
             ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, 
159
             ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, 
192
                 }
192
                 }
193
             }
193
             }
194
 
194
 
195
-            ret = ngx_pcalloc(r->pool, sizeof(ngx_str_t));
195
+            ret = ngx_calloc(r->pool, sizeof(ngx_str_t));
196
             ret->data = start_p;
196
             ret->data = start_p;
197
             ret->len = p - start_p;
197
             ret->len = p - start_p;
198
             ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, 
198
             ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, 
306
 
306
 
307
 static void ngx_http_uploadprogress_event_handler(ngx_http_request_t *r)
307
 static void ngx_http_uploadprogress_event_handler(ngx_http_request_t *r)
308
 {
308
 {
309
-    ngx_str_t                                   *id;
309
+    ngx_str_t                                   *id, *oldid;
310
     ngx_slab_pool_t                             *shpool;
310
     ngx_slab_pool_t                             *shpool;
311
     ngx_connection_t                            *c;
311
     ngx_connection_t                            *c;
312
     ngx_shm_zone_t                              *shm_zone;
312
     ngx_shm_zone_t                              *shm_zone;
320
     c = r->connection;
320
     c = r->connection;
321
 
321
 
322
     /* find node, update rest */
322
     /* find node, update rest */
323
-    id = get_tracking_id(r);
323
+    oldid = id = get_tracking_id(r);
324
     
324
     
325
     /* perform a deep copy of id */
325
     /* perform a deep copy of id */
326
     id = ngx_http_uploadprogress_strdup(id, r->connection->log);
326
     id = ngx_http_uploadprogress_strdup(id, r->connection->log);
327
     
327
     
328
+    ngx_free(oldid);
329
+		
328
     ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
330
     ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
329
                    "upload-progress: read_event_handler found id: %V", id);
331
                    "upload-progress: read_event_handler found id: %V", id);
330
     upcf = ngx_http_get_module_loc_conf(r, ngx_http_uploadprogress_module);
332
     upcf = ngx_http_get_module_loc_conf(r, ngx_http_uploadprogress_module);
419
     if (upcf->shm_zone == NULL) {
421
     if (upcf->shm_zone == NULL) {
420
         ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
422
         ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
421
                        "reportuploads no shm_zone for id: %V", id);
423
                        "reportuploads no shm_zone for id: %V", id);
424
+        ngx_free(id);
422
         return NGX_DECLINED;
425
         return NGX_DECLINED;
423
     }
426
     }
424
 
427
 
443
                        "reportuploads not found: %V", id);
446
                        "reportuploads not found: %V", id);
444
     }
447
     }
445
     ngx_shmtx_unlock(&shpool->mutex);
448
     ngx_shmtx_unlock(&shpool->mutex);
449
+	ngx_free(id);
446
 
450
 
447
     /* send the output */
451
     /* send the output */
448
     r->headers_out.content_type.len = sizeof("text/javascript") - 1;
452
     r->headers_out.content_type.len = sizeof("text/javascript") - 1;
627
     if (!upcf->track) {
631
     if (!upcf->track) {
628
         ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
632
         ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
629
                        "trackuploads not tracking in this location for id: %V", id);
633
                        "trackuploads not tracking in this location for id: %V", id);
634
+        ngx_free(id);
630
         return NGX_DECLINED;
635
         return NGX_DECLINED;
631
     }
636
     }
632
 
637
 
633
     if (upcf->shm_zone == NULL) {
638
     if (upcf->shm_zone == NULL) {
634
         ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
639
         ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
635
                        "trackuploads no shm_zone for id: %V", id);
640
                        "trackuploads no shm_zone for id: %V", id);
641
+        ngx_free(id);
636
         return NGX_DECLINED;
642
         return NGX_DECLINED;
637
     }
643
     }
638
 
644
 
653
         ngx_log_error(NGX_LOG_INFO, r->connection->log, 0,
659
         ngx_log_error(NGX_LOG_INFO, r->connection->log, 0,
654
                       "upload_progress: tracking already registered id: %V", id);
660
                       "upload_progress: tracking already registered id: %V", id);
655
 
661
 
662
+        ngx_free(id);
656
         return NGX_HTTP_INTERNAL_SERVER_ERROR;
663
         return NGX_HTTP_INTERNAL_SERVER_ERROR;
657
     }
664
     }
658
 
665
 
659
     cln = ngx_pool_cleanup_add(r->pool, sizeof(ngx_http_uploadprogress_cleanup_t));
666
     cln = ngx_pool_cleanup_add(r->pool, sizeof(ngx_http_uploadprogress_cleanup_t));
660
     if (cln == NULL) {
667
     if (cln == NULL) {
661
         ngx_shmtx_unlock(&shpool->mutex);
668
         ngx_shmtx_unlock(&shpool->mutex);
669
+        ngx_free(id);
662
         return NGX_HTTP_INTERNAL_SERVER_ERROR;
670
         return NGX_HTTP_INTERNAL_SERVER_ERROR;
663
     }
671
     }
664
 
672
 
668
     node = ngx_slab_alloc_locked(shpool, n);
676
     node = ngx_slab_alloc_locked(shpool, n);
669
     if (node == NULL) {
677
     if (node == NULL) {
670
         ngx_shmtx_unlock(&shpool->mutex);
678
         ngx_shmtx_unlock(&shpool->mutex);
679
+        ngx_free(id);
671
         return NGX_HTTP_SERVICE_UNAVAILABLE;
680
         return NGX_HTTP_SERVICE_UNAVAILABLE;
672
     }
681
     }
673
 
682
 
709
     upcln->timeout = upcf->timeout;
718
     upcln->timeout = upcf->timeout;
710
     upcln->r = r;
719
     upcln->r = r;
711
 
720
 
721
+    ngx_free(id);
722
+
712
     ctx = ngx_pcalloc(r->pool, sizeof(ngx_http_uploadprogress_module_ctx_t));
723
     ctx = ngx_pcalloc(r->pool, sizeof(ngx_http_uploadprogress_module_ctx_t));
713
     if (ctx == NULL) {
724
     if (ctx == NULL) {
714
       return NGX_ERROR;
725
       return NGX_ERROR;
957
         if (upcf->shm_zone == NULL) {
968
         if (upcf->shm_zone == NULL) {
958
             ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
969
             ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
959
                            "trackuploads no shm_zone for id: %V", id);
970
                            "trackuploads no shm_zone for id: %V", id);
971
+            ngx_free(id);							 
960
             goto finish;
972
             goto finish;
961
         }
973
         }
962
 
974
 
977
                            "trackuploads error-tracking found node for id: %V", id);
989
                            "trackuploads error-tracking found node for id: %V", id);
978
             up->err_status = r->err_status;
990
             up->err_status = r->err_status;
979
             ngx_shmtx_unlock(&shpool->mutex);
991
             ngx_shmtx_unlock(&shpool->mutex);
992
+            ngx_free(id);							 
980
             goto finish;
993
             goto finish;
981
         }
994
         }
982
 
995
 
986
         cln = ngx_pool_cleanup_add(r->pool, sizeof(ngx_http_uploadprogress_cleanup_t));
999
         cln = ngx_pool_cleanup_add(r->pool, sizeof(ngx_http_uploadprogress_cleanup_t));
987
         if (cln == NULL) {
1000
         if (cln == NULL) {
988
             ngx_shmtx_unlock(&shpool->mutex);
1001
             ngx_shmtx_unlock(&shpool->mutex);
1002
+            ngx_free(id);							 
989
             goto finish;
1003
             goto finish;
990
         }
1004
         }
991
 
1005
 
993
         node = ngx_slab_alloc_locked(shpool, n);
1007
         node = ngx_slab_alloc_locked(shpool, n);
994
         if (node == NULL) {
1008
         if (node == NULL) {
995
             ngx_shmtx_unlock(&shpool->mutex);
1009
             ngx_shmtx_unlock(&shpool->mutex);
1010
+            ngx_free(id);							 
996
             goto finish;
1011
             goto finish;
997
         }
1012
         }
998
 
1013
 
1029
 
1044
 
1030
         ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
1045
         ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
1031
                        "trackuploads error-tracking adding: %08XD", node->key);
1046
                        "trackuploads error-tracking adding: %08XD", node->key);
1047
+        ngx_free(id);							 
1032
     }
1048
     }
1033
 
1049
 
1034
   finish:
1050
   finish:

Загрузка…
Отмена
Сохранить