]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
FS-12025: [mod_spandsp] FreeSWITCH crashes on reloadxml when spandsp tone detection...
authorAndrey Volk <andywolk@gmail.com>
Fri, 23 Aug 2019 08:16:22 +0000 (12:16 +0400)
committerAndrey Volk <andywolk@gmail.com>
Thu, 29 Aug 2019 22:20:18 +0000 (02:20 +0400)
src/mod/applications/mod_spandsp/mod_spandsp.c
src/mod/applications/mod_spandsp/mod_spandsp.h
src/mod/applications/mod_spandsp/mod_spandsp_dsp.c

index f674d14811e57adddfeb47e972e1efec9419ce5f..35d0cb585f70175ab1d9a3fe803e7c2f760de64f 100644 (file)
@@ -485,7 +485,7 @@ static void destroy_descriptor(void *ptr)
 {
     tone_descriptor_t *d = (tone_descriptor_t *) ptr;
 
-    super_tone_rx_free_descriptor(d->spandsp_tone_descriptor);
+       tone_descriptor_destroy(d);
 }
 
 switch_status_t load_configuration(switch_bool_t reload)
index 7ffd334ef36040c18b8b748a51b73d720766a13b..0863831b3caa7b311d7ad8a2c265bedcd47b9e4e 100644 (file)
@@ -133,6 +133,7 @@ typedef struct tone_descriptor tone_descriptor_t;
 
 
 switch_status_t tone_descriptor_create(tone_descriptor_t **descriptor, const char *name, switch_memory_pool_t *memory_pool);
+void tone_descriptor_destroy(tone_descriptor_t *descriptor);
 int tone_descriptor_add_tone(tone_descriptor_t *descriptor, const char *name);
 switch_status_t tone_descriptor_add_tone_element(tone_descriptor_t *descriptor, int tone_id, int freq1, int freq2, int min, int max);
 
index 9a43271c9937cd827e6fbc9d157c7f7f9626a0df..fca74635e8b31c210c737a7a389493d0e54a67ed 100644 (file)
@@ -637,6 +637,20 @@ switch_status_t tone_descriptor_create(tone_descriptor_t **descriptor, const cha
        return SWITCH_STATUS_SUCCESS;
 }
 
+/**
+ * Destroy the tone descriptor
+ *
+ * @param descriptor the descriptor to create
+ * @return void
+ */
+void tone_descriptor_destroy(tone_descriptor_t *descriptor)
+{
+       if (descriptor->spandsp_tone_descriptor) {
+               super_tone_rx_free_descriptor(descriptor->spandsp_tone_descriptor);
+               descriptor->spandsp_tone_descriptor = NULL;
+       }
+}
+
 /**
  * Add a tone to the tone descriptor
  *
@@ -711,6 +725,48 @@ static void tone_segment_callback(void *user_data, int f1, int f2, int duration)
        }
 }
 
+/**
+ * Duplicate the tone descriptor
+ *
+ * @param descriptor the descriptor to use
+ * @param memory_pool the pool to use
+ * @return pointer to a copy of descriptor
+ */
+static tone_descriptor_t *tone_descriptor_dup(tone_descriptor_t *descriptor, switch_memory_pool_t *pool)
+{
+       tone_descriptor_t *desc = NULL;
+       int t = 0, s = 0, tone_count = 0;
+
+       if (descriptor && pool) {
+               if (tone_descriptor_create(&desc, descriptor->name, pool) != SWITCH_STATUS_SUCCESS) {
+                       return NULL;
+               }
+
+               tone_count = descriptor->idx + 1;
+
+               for (t = 0; t < tone_count; t++) {
+                       int tone_id = tone_descriptor_add_tone(desc, descriptor->tone_keys[t]);
+                       if (-1 != tone_id) {
+                               int step = descriptor->spandsp_tone_descriptor->tone_segs[tone_id];
+                               for (s = 0; s < step; s++) {
+                                       super_tone_rx_segment_t segment = descriptor->spandsp_tone_descriptor->tone_list[tone_id][s];
+                                       int f1 = (segment.f1 == -1 ? 0 : descriptor->spandsp_tone_descriptor->pitches[segment.f1][0]);
+                                       int f2 = (segment.f2 == -1 ? 0 : descriptor->spandsp_tone_descriptor->pitches[segment.f2][0]);
+                                       int min = segment.min_duration / 8;
+                                       int max = (segment.max_duration == 0x7FFFFFFF ? 0 : segment.max_duration / 8);
+                                       tone_descriptor_add_tone_element(desc, tone_id, f1, f2, min, max);
+                               }
+                       } else {
+                               tone_descriptor_destroy(desc);
+                               desc = NULL;
+                               break;
+                       }
+               }
+       }
+
+       return desc;
+}
+
 /**
  * Allocate the tone detector
  *
@@ -723,11 +779,8 @@ static void tone_segment_callback(void *user_data, int f1, int f2, int duration)
 static switch_status_t tone_detector_create(switch_core_session_t *session, tone_detector_t **detector, tone_descriptor_t *descriptor)
 {
        tone_detector_t *ldetector = switch_core_session_alloc(session, sizeof(tone_detector_t));
-       tone_descriptor_t *desc = switch_core_session_alloc(session, sizeof(tone_descriptor_t));
-
-       memcpy(desc, descriptor, sizeof(tone_descriptor_t));
 
-       ldetector->descriptor = desc;
+       ldetector->descriptor = tone_descriptor_dup(descriptor, switch_core_session_get_pool(session));
        ldetector->debug = spandsp_globals.tonedebug;
        ldetector->session = session;
        *detector = ldetector;
@@ -777,6 +830,10 @@ static void tone_detector_destroy(tone_detector_t *detector)
                        super_tone_rx_free(detector->spandsp_detector);
                        detector->spandsp_detector = NULL;
                }
+               if (detector->descriptor) {
+                       tone_descriptor_destroy(detector->descriptor);
+                       detector->descriptor = NULL;
+               }
        }
 }