#include <stdio.h>
#include <stdlib.h>
struct Inner {
int value;
};
struct Outer {
struct Inner *innerPtr;
struct Outer *next;
};
void processOuter(struct Outer *outer) {
if (outer == NULL) {
return;
}
struct Outer *current = outer;
struct Outer *prev = NULL;
while (current != NULL) {
if (current->innerPtr == NULL) {
current->innerPtr = (struct Inner *)malloc(sizeof(struct Inner));
if (current->innerPtr == NULL) {
// 内存分配失败,处理异常
fprintf(stderr, "内存分配失败\n");
// 释放之前分配的内存
while (prev != NULL) {
struct Outer *temp = prev;
prev = prev->next;
if (temp->innerPtr != NULL) {
free(temp->innerPtr);
}
free(temp);
}
return;
}
current->innerPtr->value = -1;
}
if (current->next == NULL) {
printf("下一个Outer节点为空\n");
}
prev = current;
current = current->next;
}
// 释放所有分配的内存
current = outer;
while (current != NULL) {
struct Outer *temp = current;
current = current->next;
if (temp->innerPtr != NULL) {
free(temp->innerPtr);
}
free(temp);
}
}